2011-01-19 33 views
1

我無法弄清楚如何爲這個手風琴家添加一個活躍狀態。我覺得我很近,但我必須點擊兩次,以便箭頭狀態改變。任何想法我做錯了什麼?爲我的生活添加一個jquery活動狀態給一個手風琴家

$('ul.expand').each(function(){ 
    $('li.md', this).filter(':first').addClass('top').end().filter(':not(.open)').next().hide(); 
    $('li.md', this).click(function(){ 
     if($(this).hasClass('open')) { 
      $(this).find('.arrow').addClass('active'); 
      return false; 
     } else { 
      $(this).find('.arrow').removeClass('active'); 
      $(this).parent().find('li.md').removeClass('open').next().filter(':visible').slideUp(); 
      $(this).addClass('open').next().slideDown(); 
      $(this).find('.arrow').addClass('active'); 
     } 
    }); 
}); 

這裏是HTML:

http://www.lastyearsloss.com/mav/mobile/

+0

從查看你的代碼,我會說可以做很多優化。 – 2011-01-19 16:38:59

+0

您鏈接中的JavaScript與您在此處發佈的內容不同:S – 2011-01-19 16:44:12

回答

2

在else中刪除所有活動類,因爲手風琴只允許1個活動成員。

$('li.md').find('.arrow').removeClass('active'); // remove all actives 
$(this).find('.arrow').addClass('active'); // activate current 
0
$('li.md').find('.arrow.active').removeClass('active'); 

你試過了嗎?

+0

是的。看起來我必須點擊標題欄兩次才能更改箭頭。 – Robert 2011-01-19 16:40:58

相關問題