我发现了一种方法来自己做。不是很优雅或短小,但它运作良好,并保持打开子菜单,以防它包含当前菜单项。该解决方案仅限于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");
});
如何使用另一个插件? http://www.jqueryrain.com/demo/jquery-treeview/ 或者你想使用那个插件? –
我想保持这一点,因为我几乎完成了CSS和所有。刚刚被子菜单的滑动切换卡住了。无论如何Thnaks的建议。 – chicky