2011-07-12 57 views
0

我的網站:http://www.daysofthedead.net問題與jQuery切換/動畫

我已經在屏幕的右側,由2個滑動面板。一個用於Facebook,另一個用於Twitter。您點擊Facebook標籤並打開,然後如果您在Facebook面板仍然打開的情況下點擊Twitter標籤,則Facebook將關閉,Twitter將打開,反之亦然。

我的問題: 您點擊一次打開Facebook,然後打開Twitter。之後,您必須單擊每個選項卡兩次,除非在打開第二個面板之前關閉面板。

有人可以看看我的代碼下面,並幫我找出它爲什麼這樣做?

看看這裏的代碼:http://jsfiddle.net/Draven/4BQAs/

回答

1

我認爲切換是創造了一些問題,在這種情況下,你可以只用點擊:

$('.panel-tab').click(function(event) { 
    var that = this; 
    if ($('.active').length > 0) { 
     $('.active').animate({ 
      marginRight: '0' 
     }, 1000,'linear', function() { 
      var targetClosed = $(this).find('a').data('target'); 
      var targetOpen = $(that).data('target'); 
      if (targetClosed != targetOpen){ 
      $('#panel-' + targetOpen).animate({ 
       marginRight: '292' 
      }, 1000).addClass('active'); 
     } 
     }).removeClass('active'); 
    } else { 
     $('#panel-' + $(this).data('target')).animate({ 
      marginRight: '292' 
     }, 1000).addClass('active'); 
    } 
}); 

fidlle這裏:http://jsfiddle.net/4BQAs/8/

+0

哦, 太棒了。謝謝! – Draven