From 85da00866070dd6060b09598779f638d096498de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:09:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20dropdown=20=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E8=A7=A6=E5=8F=91=E7=9A=84=E4=BA=8B=E4=BB=B6=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BF=9B=E8=A1=8C=E5=BB=B6=E8=BF=9F=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=20=E8=8B=A5=E4=B8=BA=E9=BC=A0=E6=A0=87=E7=A7=BB=E5=85=A5?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=EF=BC=8C=E5=88=99=E5=BB=B6=E8=BF=9F=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=9B=E5=85=B6=E4=BB=96=E4=BA=8B=E4=BB=B6=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/dropdown.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index ed0fefcd..4af95785 100644 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -421,15 +421,22 @@ layui.define(['jquery', 'laytpl', 'lay', 'util'], function(exports){ // 解除上一个事件 if(that.prevElem) that.prevElem.off(options.trigger, that.prevElemCallback); + + // 是否鼠标移入时触发 + var isMouseEnter = options.trigger === 'mouseenter'; // 记录被绑定的元素及回调 that.prevElem = options.elem; that.prevElemCallback = function(e){ clearTimeout(thisModule.timer); that.e = e; - thisModule.timer = setTimeout(function(){ - that.render(); - }, that.normalizedDelay().show); + + // 若为鼠标移入事件,则延迟触发 + isMouseEnter ? ( + thisModule.timer = setTimeout(function(){ + that.render(); + }, that.normalizedDelay().show) + ) : that.render(); e.preventDefault(); }; @@ -438,7 +445,7 @@ layui.define(['jquery', 'laytpl', 'lay', 'util'], function(exports){ options.elem.on(options.trigger, that.prevElemCallback); // 如果是鼠标移入事件 - if(options.trigger === 'mouseenter'){ + if (isMouseEnter) { // 执行鼠标移出事件 options.elem.on('mouseleave', function(){ that.delayRemove();