layui实现鼠标移入/移出时显示/隐藏tips

layui实现鼠标移入/移出时显示/隐藏tips弹窗

注:其它弹窗亦可按照此方法实现相同效果

鼠标移入 dom 或 tips 区域,显示 tips 弹窗;

鼠标移出 dom 或 tips 区域,隐藏 tips 窗口;

html 复制代码
<div id="box">鼠标移入移出</div>

<script src="./js/jquery-1.11.0.min.js"></script>
<script src="./js/layui.js"></script>
<script type="text/javascript">
    layui.use('layer', function() {
        const layer = layui.layer;
        let timer_event, layer_tips, tips_show = false
        
        $('#box').on({
            'mouseenter': function () {
                clearTimeout(timer_event)
                if(tips_show) return
                layer_tips = layer.tips(`<p id='tips-box'>tips content</p>`, $(this), {
                    time:0,
                    closeBtn: '1',
                    maxWidth: 200,
                    tips: 3,
                    success: function () {
                        tips_show = true
                        $('.layui-layer-tips .layui-layer-content').css({
                            'padding': '10px',
                            'border': '1px solid #666',
                        })
                        $('#tips-box').on({
                            'mouseenter': function () {
                                clearTimeout(timer_event)
                            },
                            'mouseleave': function () {
                                hideTips()
                            }
                        })
                    }
                }) 
            },
            'mouseleave': function () {
                hideTips()
            }
        })
        
        function hideTips() {
            clearTimeout(timer_event)
            timer_event = setTimeout(()=>{
                layer.close(layer_tips)
                tips_show = false
            }, 200)
        }
    })
</script>
相关推荐
jiayong2313 分钟前
第 8 课:开始引入组合式函数
前端·javascript·学习
田八16 分钟前
聊聊AI的发展史,AI的爆发并不是偶然
前端·人工智能·程序员
zhanghongbin0126 分钟前
AI 采集器:Claude Code、OpenAI、LiteLLM 监控
java·前端·人工智能
IT_陈寒32 分钟前
Python的列表推导式里藏了个坑,差点让我加班到凌晨
前端·人工智能·后端
吴声子夜歌40 分钟前
ES6——正则的扩展详解
前端·mysql·es6
天若有情6731 小时前
【C++原创开源】formort.h:一行头文件,实现比JS模板字符串更爽的链式拼接+响应式变量
开发语言·javascript·c++·git·github·开源项目·模版字符串
天***88521 小时前
Edge 浏览器离线绿色增强版+官方安装包,支持win7等系统
前端·edge
漫游的渔夫1 小时前
别再直接 `json.loads` 了!AI 返回的 JSON 坑位指南
前端·人工智能
软件工程师文艺1 小时前
从0到1:Claude Code如何用React构建CLI应用
前端·react.js·前端框架
M ? A2 小时前
Vue 迁移 React 实战:VuReact 一键自动化转换方案
前端·vue.js·经验分享·react.js·开源·自动化·vureact