浏览代码

修改右侧tab点击时多级菜单不选中的bug

笔下光年 3 年之前
父节点
当前提交
9883f862b6
共有 2 个文件被更改,包括 37 次插入33 次删除
  1. 36 32
      js/bootstrap-multitabs/multitabs.js
  2. 1 1
      js/index.min.js

+ 36 - 32
js/bootstrap-multitabs/multitabs.js

@@ -551,19 +551,17 @@ if (typeof jQuery === "undefined") {
                 $navHasSubnav = $navObj.parents('.nav-item'),
                 $viSubHeight  = $navHasSubnav.siblings().find('.nav-subnav:visible').outerHeight();
             
-            $('.nav-item').each(function(i){
-                if ($(this).hasClass('active') && !$navObj.parents('.nav-item').last().hasClass('active')) {
-                    $(this).removeClass('active').removeClass('open');
-                    $(this).find('.nav-subnav:visible').slideUp(500);
-                    if (window.innerWidth > 1024 && $('body').hasClass('lyear-layout-sidebar-close')) {
-                        $(this).find('.nav-subnav').hide();
-                    }
+            $('.nav-drawer .nav-item').not($navHasSubnav).each(function() {
+                if (window.innerWidth > 1024 && $('body').hasClass('lyear-layout-sidebar-close')) {
+                    $(this).find('.nav-subnav').hide();
                 }
+                $(this).find('.nav-subnav:visible').slideUp(500);
+                $(this).removeClass('active open');
             });
             
             $('.nav-drawer').find('li').removeClass('active');
             $navObj.parent('li').addClass('active');
-            $navHasSubnav.first().addClass('active');
+            $navHasSubnav.addClass('active');
             
             // 当前菜单无子菜单
             if (!$navObj.parents('.nav-item').first().is('.nav-item-has-subnav')) {
@@ -571,37 +569,43 @@ if (typeof jQuery === "undefined") {
                 $('.lyear-layout-sidebar-scroll').animate({scrollTop: hht}, 300);
             }
             
-            if ($navObj.parents('ul.nav-subnav').last().is(':hidden')) {
-                $navObj.parents('ul.nav-subnav').last().slideDown(500, function(){
-                    $navHasSubnav.last().addClass('open');
-		            var scrollHeight  = 0,
-                        $scrollBox    = $('.lyear-layout-sidebar-scroll'),
-		                pervTotal     = $navHasSubnav.last().prevAll().length,
-		                boxHeight     = $scrollBox.outerHeight(),
-	                    innerHeight   = $('.sidebar-main').outerHeight(),
-                        thisScroll    = $scrollBox.scrollTop(),
-                        thisSubHeight = $(this).outerHeight(),
-                        footHeight    = 121;
-		            
-		            if (footHeight + innerHeight - boxHeight >= (pervTotal * 48)) {
-		                scrollHeight = pervTotal * 48;
-		            }
-                    if ($navHasSubnav.length == 1) {
-                        $scrollBox.animate({scrollTop: scrollHeight}, 300);
-                    } else {
-                        // 子菜单操作
-                        if (typeof($viSubHeight) != 'undefined' && $viSubHeight != null) {
-                            scrollHeight = thisScroll + thisSubHeight - $viSubHeight;
+            var $sideDownObj = $navObj.parents('ul.nav-subnav').filter(':hidden');
+            var $sideDownLen = $sideDownObj.length;
+            
+            $sideDownObj.each(function(i) {
+                $(this).slideDown(500, function() {
+                    $(this).parent('.nav-item').addClass('open');
+                    
+                    if (i === $sideDownLen - 1) {
+		                var scrollHeight  = 0,
+                            $scrollBox    = $('.lyear-layout-sidebar-scroll'),
+		                    pervTotal     = $navHasSubnav.last().prevAll().length,
+		                    boxHeight     = $scrollBox.outerHeight(),
+	                        innerHeight   = $('.sidebar-main').outerHeight(),
+                            thisScroll    = $scrollBox.scrollTop(),
+                            thisSubHeight = $(this).outerHeight(),
+                            footHeight    = 121;
+		                
+		                if (footHeight + innerHeight - boxHeight >= (pervTotal * 48)) {
+		                    scrollHeight = pervTotal * 48;
+		                }
+                        if ($navHasSubnav.length == 1) {
                             $scrollBox.animate({scrollTop: scrollHeight}, 300);
                         } else {
-                            if ((thisScroll + boxHeight - $scrollBox[0].scrollHeight) == 0) {
-                                scrollHeight = thisScroll - thisSubHeight;
+                            // 子菜单操作
+                            if (typeof($viSubHeight) != 'undefined' && $viSubHeight != null) {
+                                scrollHeight = thisScroll + thisSubHeight - $viSubHeight;
                                 $scrollBox.animate({scrollTop: scrollHeight}, 300);
+                            } else {
+                                if ((thisScroll + boxHeight - $scrollBox[0].scrollHeight) == 0) {
+                                    scrollHeight = thisScroll - thisSubHeight;
+                                    $scrollBox.animate({scrollTop: scrollHeight}, 300);
+                                }
                             }
                         }
                     }
                 });
-            }
+            });
         },
 
         /**

+ 1 - 1
js/index.min.js

@@ -98,7 +98,7 @@ jQuery( function() {
     $(document).on('click', '.nav-item .multitabs', function() {
         $('.nav-item').removeClass('active');
         $('.nav-subnav li').removeClass('active');
-        $(this).parent('li').addClass('active');
+        $(this).parents('li').addClass('active');
         $(this).parents('.nav-item-has-subnav').addClass('open').first().addClass('active');
     });
 });