使用layer.tips实现鼠标悬浮时触发事件提示消息实现

时间:2023-03-09 17:00:34
使用layer.tips实现鼠标悬浮时触发事件提示消息实现

代码:

<body>
<label id="test" onmouseover="show('test')">
你瞅啥!?过来试试!
</label>
</body>

方法一:

<script>
function show(id) {
layer.tips("左边么么哒", "#"+id+"", {
tips: [4, "#4794ec"]
});
}
</script>

实现效果:

使用layer.tips实现鼠标悬浮时触发事件提示消息实现

  如图所示,当鼠标悬浮在label标签范围内时,通过layer.tips弹出提示消息。其中tips:中设置为4,表示左边有空间时在左边弹出消息框;

  也可设置为其它:

    1——上方;2——右方;3——方;

  详情可查看:https://www.layui.com/doc/modules/layer.html#tips

方法二:(通过过滤器去筛选)

$("label").not(":last").mouseover(function() {
layer.tips($(this).text(), this, {
tips: [3, "#4794ec"]
});
});

其中 .not(":last") 表示排除最后一个,整体意思是:除过最后一个label标签外的其他所有label标签。