2015-08-27 68 views
0

我正在尝试从这几天开始获得此权利: jQuery.mmenu的子菜单应该顺利切换,并且我总是希望一次只打开一个子菜单。另外我喜欢保持功能,如果打开一个页面当前菜单元素是可见的。如何切换垂直jQuery.mmenu子菜单?

我确实在这里设置了js fiddle

也许有人可以给我一个提示如何应用的.next()选择 - 在是要走的道路情况......

我设法创建幻灯片切换,但切换的所有子菜单当然:

$(document).ready(function() { 
    $(".mm-vertical ul.level2").hide(); 
    $(".mm-vertical ul.level3").hide(); 
    $(".level1 a.mm-next").click(function() { 
    $(".mm-vertical ul.level2").slideToggle("slow", function() {}); 
    }); 
    }); 
+0

如何使用另一个插件? http://www.jqueryrain.com/demo/jquery-treeview/ 或者你想使用那个插件? –

+0

我想保持这一点,因为我几乎完成了CSS和所有。刚刚被子菜单的滑动切换卡住了。无论如何Thnaks的建议。 – chicky

回答

0

我发现了一种方法来自己做。不是很优雅或短小,但它运作良好,并保持打开子菜单,以防它包含当前菜单项。该解决方案仅限于3个级别。我添加了类“level1”,“level2”,因为我通过typo3生成菜单的html。

$(".mm-vertical ul").hide(); 
$(".mm-vertical ul.level3").hide(); 


$(".level1 a.mm-next").on('click', function(){ 
var element = $(this).parent('li'); 
if (element.hasClass('mm-opened')) { 
    element.find('ul.level2').slideUp("slow", function() {}); 
    } 
    else { 
     element.find('ul.level2').slideDown("slow", function() {}); 
     element.siblings('li').children('ul').slideUp("slow", function() {}); 
     element.siblings('li').removeClass('mm-opened'); 
     element.siblings('li').find('li').removeClass('mm-opened'); 
     element.siblings('li').find('ul').slideUp("slow", function() {}); 
     } 
      }); 

$(".level2 a.mm-next").on('click', function(){ 
var element = $(this).parent('li'); 
if (element.hasClass('mm-opened')) { 
    element.find('ul.level3').slideUp("slow", function() {}); 
    } 
    else { 
     element.find('ul.level3').slideDown("slow", function() {}); 
       element.siblings('li').children('ul').slideUp("slow", function() {}); 
     element.siblings('li').removeClass('mm-opened'); 
     element.siblings('li').find('li').removeClass('mm-opened'); 
     element.siblings('li').find('ul').slideUp("slow", function() {}); 
     } 
      }); 
$('.level2.mm-selected').each(function(){ 
$(this).parent().removeAttr("style"); 
}); 
$('.level2.mm-opened').each(function(){ 
$(this).parent().removeAttr("style"); 
var element = $('.level2.mm-opened'); 
element.find('ul.level3').removeAttr("style"); 
}); 
$('.level3.mm-selected').each(function(){ 
$(this).parent().removeAttr("style"); 
}); 
$('.level3.mm-opened').each(function(){ 
$(this).parent().removeAttr("style"); 



});