From a1491c1936952e79a12f78c30fbf94901a05e2b1 Mon Sep 17 00:00:00 2001 From: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Mon, 14 Oct 2024 23:42:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(element-nav):=20=E5=8A=A8=E6=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=83=E7=B4=A0=E6=B8=B2=E6=9F=93=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=20(#2276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/element.js | 68 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/modules/element.js b/src/modules/element.js index 8efdf3f3..e5fe5b99 100644 --- a/src/modules/element.js +++ b/src/modules/element.js @@ -499,44 +499,44 @@ layui.define('jquery', function(exports){ var itemElem = othis.find('.'+NAV_ITEM); // hover 滑动效果 - if (!othis.find('.'+NAV_BAR)[0]) { - othis.append(bar); - ( othis.hasClass(NAV_TREE) - ? itemElem.find('dd,>.'+ NAV_TITLE) - : itemElem - ).on('mouseenter', function() { - follow.call(this, bar, othis, index); - }).on('mouseleave', function() { // 鼠标移出 - // 是否为垂直导航 - if (othis.hasClass(NAV_TREE)) { + var hasBarElem = othis.find('.'+NAV_BAR)[0]; + if (hasBarElem) hasBarElem.remove(); + othis.append(bar); + ( othis.hasClass(NAV_TREE) + ? itemElem.find('dd,>.'+ NAV_TITLE) + : itemElem + ).off('mouseenter.lay_nav').on('mouseenter.lay_nav', function() { + follow.call(this, bar, othis, index); + }).off('mouseleave.lay_nav').on('mouseleave.lay_nav', function() { // 鼠标移出 + // 是否为垂直导航 + if (othis.hasClass(NAV_TREE)) { + bar.css({ + height: 0, + opacity: 0 + }); + } else { + // 隐藏子菜单 + clearTimeout(timerMore[index]); + timerMore[index] = setTimeout(function(){ + othis.find('.'+ NAV_CHILD).removeClass(SHOW); + othis.find('.'+ NAV_MORE).removeClass(NAV_MORE +'d'); + }, 300); + } + }); + + // 鼠标离开当前菜单时 + othis.off('mouseleave.lay_nav').on('mouseleave.lay_nav', function() { + clearTimeout(timer[index]) + timeEnd[index] = setTimeout(function() { + if (!othis.hasClass(NAV_TREE)) { bar.css({ - height: 0, + width: 0, + left: bar.position().left + bar.width() / 2, opacity: 0 }); - } else { - // 隐藏子菜单 - clearTimeout(timerMore[index]); - timerMore[index] = setTimeout(function(){ - othis.find('.'+ NAV_CHILD).removeClass(SHOW); - othis.find('.'+ NAV_MORE).removeClass(NAV_MORE +'d'); - }, 300); } - }); - - // 鼠标离开当前菜单时 - othis.on('mouseleave', function() { - clearTimeout(timer[index]) - timeEnd[index] = setTimeout(function() { - if (!othis.hasClass(NAV_TREE)) { - bar.css({ - width: 0, - left: bar.position().left + bar.width() / 2, - opacity: 0 - }); - } - }, TIME); - }); - } + }, TIME); + }); // 展开子菜单 itemElem.find('a').each(function() {