2012-12-14 77 views
2

我使用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{ 
      } 
     } 
}); 
;​ 

我有困難,搞清楚如何從關閉和開啓再次子菜單鏈接時,內是停止活動的(預先打開)子菜單點擊。

任何想法我做錯了什麼?

回答

1

刪除class="current-parent" 它不應該顯示子打開。 在這裏檢查http://jsfiddle.net/fPWeq/1/

+0

我希望子被預先打開。我不想讓它關閉,然後在點擊一個子鏈接時再次打開。 – user18577

+0

給'class =「current-parent」一個活躍的類,使它變成'class =「當前 - 父活動」' – Chanckjh

+0

它有幫助嗎?這是你的問題的答案嗎? – Chanckjh