我使用教程中的这段代码:
$(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秒与其他幻灯片一样?
答案 0 :(得分: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 :(得分:1)
不要让它自动执行功能:
function autoAdvance(){
// Simulating a click on the next arrow.
timeOut = setTimeout(autoAdvance,2000);
$('.slider_rightlink').trigger('click',[true]);
};
timeOut = setTimeout(autoAdvance,2000);