我有一个类似的脚本:
(function($){
$(document).ready(function(){
var sliderInstance = $('#content-slider').mySlider({
directionNavEnabled: true,
directionNavAutoHide: false,
welcomeScreenEnabled:false,
imageAlignCenter:true
}).data('mySlider');
$("#button-id").click(function() {
sliderInstance.next();
});
});
})(jQuery);
如何每隔3秒执行 sliderInstance.next(); ,而不是点击#button-id
答案 0 :(得分:5)
如果您愿意,可以每3秒生成一次合成点击事件。这需要最少量的额外代码:
setInterval(function() { $("#button-id").click(); }, 3000);
这将每隔3秒在按钮上生成一次点击事件。
如果你想让它直接调用脚本:
setInterval(function() { sliderInstance.next(); }, 3000);
请注意,setInterval
调用需要与sliderInstance
的定义位于同一范围内,这可能会使第一个版本更容易实现或更难实现,具体取决于您的代码是如何实现的结构