2011-10-03 84 views
0

我使用這段代碼tutorialzine:推進幻燈片jQuery中

$(window).load(function(){ 

    // The window.load event guarantees that all the images are loaded before the auto-advance begins. 
    var timeOut = null; 

    $('#slider_navigator .arrow, #slider_navigator .dot').click(function(e,simulated){ 
     // The simulated parameter is set by the trigger method. 
     if(!simulated){ 
      // A real click occured. Cancel the auto advance animation. 
      clearTimeout(timeOut); 
     } 
    }); 

    // A self executing named function expression: 
    (function autoAdvance(){ 
     // Simulating a click on the next arrow. 
     timeOut = setTimeout(autoAdvance,2000); 
     $('.slider_rightlink').trigger('click',[true]); 
    })(); 

}); 

這就像預期的,除了一兩件事,當我加載頁面的第一張幻燈片立即先進。加載後,它與其他幻燈片很好地旋轉。

我該如何改變它,使其顯示第一張幻燈片2秒鐘?

回答

1
$(window).load(function(){setTimeout(function(){ 

    // The window.load event guarantees that all the images are loaded before the auto-advance begins. 
    var timeOut = null; 

    $('#slider_navigator .arrow, #slider_navigator .dot').click(function(e,simulated){ 
     // The simulated parameter is set by the trigger method. 
     if(!simulated){ 
      // A real click occured. Cancel the auto advance animation. 
      clearTimeout(timeOut); 
     } 
    }); 

    // A self executing named function expression: 
    (function autoAdvance(){ 
     // Simulating a click on the next arrow. 
     timeOut = setTimeout(autoAdvance,2000); 
     $('.slider_rightlink').trigger('click',[true]); 
    })(); 

},2000);} 

); 

有可能是一個setTimeout jQuery函數,但這將工作。

+1

有時生命是如此複雜。謝謝! – klaaz

+0

沒問題。讓我知道它是否成功:D – mowwwalker

1

不讓它自我執行的函數:

function autoAdvance(){ 
    // Simulating a click on the next arrow. 
    timeOut = setTimeout(autoAdvance,2000); 
    $('.slider_rightlink').trigger('click',[true]); 
}; 
timeOut = setTimeout(autoAdvance,2000); 
+0

兩個解決方案的一個問題,兩個作品!謝謝! – klaaz

+0

細微的差異。這一個,點擊前2秒會取消。 Walkerneo的,一直到第一步都沒有成立。 –