我将以下 jQuery 用于手风琴菜单:http: //jsfiddle.net/fPWeq/
rel = 0;
$('.sub-menu').hover(function(){ // findind mouse postion
rel = 1; // if mouse on submenu
}, function(){
rel = 0; // if mouse out submenu
});
$('.menu > li').live("click",function(){
if(!$(this).hasClass("active")){ // if not already opened
$('.sub-menu').slideUp(); // hide all other submenu
$('.sub-menu',this).slideDown(); // show which your clicked
$(".menu > li").remove('active'); // remove all active class in li
$(this).addClass('active'); //adding active class which your clicked li
}
else{
if(rel==0){
$('.sub-menu').slideUp(); // if clicked already opend parent that will close
$(this).removeClass('active'); // remove all active class
}
else{
}
}
});
;
当单击其中的子菜单链接时,我很难弄清楚如何停止活动(预先打开的)子菜单关闭和再次打开。
任何想法我做错了什么?