From 235548fb85841e6c0e90c6a0ac47280c07dfca92 Mon Sep 17 00:00:00 2001 From: morning-star <1453017105@qq.com> Date: Wed, 18 Oct 2023 19:34:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20nav=20=E5=9E=82=E7=9B=B4?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E5=B1=95=E5=BC=80=E6=94=B6=E7=BC=A9=E7=9A=84?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E6=95=88=E6=9E=9C=20(#1396)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化 nav 垂直导航展开收缩的动画效果 * 优化 nav 垂直导航在快速点击展开收缩的动画效果 避免生成冗余 style 属性值 * 微调 nav 代码段落顺序 * 优化 nav 动画状态判断 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com> --- src/modules/element.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/modules/element.js b/src/modules/element.js index 1c7ba291..f9617204 100644 --- a/src/modules/element.js +++ b/src/modules/element.js @@ -289,19 +289,22 @@ layui.define('jquery', function(exports){ } // 若为垂直菜单 - if(parents.hasClass(NAV_TREE)){ + if (parents.hasClass(NAV_TREE)) { var NAV_ITEMED = NAV_ITEM + 'ed'; var NAV_EXPAND = 'layui-nav-expand'; - var isNone = child.css('display') === 'none'; + var needExpand = !(parent.hasClass(NAV_EXPAND) || parent.hasClass(NAV_ITEMED)); + + // 是否正处于动画中的状态 + if (child.is(':animated')) return; child.removeClass(NAV_ANIM); - + // 若有子菜单,则展开 - if(child[0]){ + if (child[0]) { child.stop().slideToggle(200, function() { - isNone || parent.removeClass(NAV_ITEMED); + needExpand || parent.removeClass(NAV_ITEMED); }); - parent[isNone ? 'addClass': 'removeClass'](NAV_EXPAND); + parent[needExpand ? 'addClass': 'removeClass'](NAV_EXPAND); // 手风琴 if(typeof parents.attr('lay-accordion') === 'string' || parents.attr('lay-shrink') === 'all'){ // 收缩兄弟项