2013-08-28 125 views
0

我是一個新手,仍在學習,我無法完全解決問題。我有下面的代碼,我想添加自動播放功能的滑塊。很欣賞幫助。Javascript滑塊自動播放

$('.feature-selection').click(function() { 
     if (!$(this).hasClass('active-feature')) { 
      var featureID = '#' + $(this).attr('data-feature-id'); 
      $('.active-feature').removeClass('active-feature'); 
      $(this).addClass('active-feature'); 
      $('.active-feature-detail').addClass('fadeOutLeftBig'); 
      setTimeout(function() { 
       $('.fadeOutLeftBig').removeClass('active-feature-detail'); 
      }, 500); 
      setTimeout(function() { 
       $('.fadeOutLeftBig').removeClass('fadeOutLeftBig'); 
      }, 600); 
      $(featureID).addClass('fadeInRightBig'); 
      var that = featureID; 
      setTimeout(function() { 
       $(that).removeClass('fadeInRightBig'); 
      }, 1000); 
      $(featureID).addClass('active-feature-detail'); 
      var newFeatureHeight = $(featureID).height() + 88; 

      $('#feature-detail-holder').css('min-height', newFeatureHeight); 
     } 
    }); 

回答

0
var interval = null; 
$('#autoplay-button').click(function(){ 
    interval = setInterval(function(){ 
     $('.feature-selection').trigger('click'); 
    }, 10000); 
}); 

$('#stop-autoplay-button').click(function(){ 
    clearInterval(interval); 
}); 

$('.feature-selection').click(function() { 
    if (!$(this).hasClass('active-feature')) { 
     var featureID = '#' + $(this).attr('data-feature-id'); 
     $('.active-feature').removeClass('active-feature'); 
     $(this).addClass('active-feature'); 
     $('.active-feature-detail').addClass('fadeOutLeftBig'); 
     setTimeout(function() { 
      $('.fadeOutLeftBig').removeClass('active-feature-detail'); 
     }, 500); 
     setTimeout(function() { 
      $('.fadeOutLeftBig').removeClass('fadeOutLeftBig'); 
     }, 600); 
     $(featureID).addClass('fadeInRightBig'); 
     var that = featureID; 
     setTimeout(function() { 
      $(that).removeClass('fadeInRightBig'); 
     }, 1000); 
     $(featureID).addClass('active-feature-detail'); 
     var newFeatureHeight = $(featureID).height() + 88; 

     $('#feature-detail-holder').css('min-height', newFeatureHeight); 
    } 
}); 
+0

我可能是智障,但如何運作的?我嘗試了不同的方法,現在卡住了:/ –

+0

滑塊的整個引擎都是在'.feature-selection'上單擊事件引發時調用的函數中完成的。我寫的想法是,你設置了一個觸發'.feature-selection'元素的點擊事件的時間間隔。 –