Javascript jquery-10秒后停止自动播放-环岛
我用插件制作了一个自动播放的幻灯片。工作正常,但几秒钟后我想停止自动播放。我阅读了文档并尝试了“autoplayDuration”,但它不是看起来的那样:P 那么,有什么提示或暗示我该怎么做?Javascript jquery-10秒后停止自动播放-环岛,javascript,jquery,slideshow,Javascript,Jquery,Slideshow,我用插件制作了一个自动播放的幻灯片。工作正常,但几秒钟后我想停止自动播放。我阅读了文档并尝试了“autoplayDuration”,但它不是看起来的那样:P 那么,有什么提示或暗示我该怎么做? 谢谢。您可以在开始时使用回调。比如: function stopRoundaboutAfterAWhile() { setTimeout(function() { .roundabout("stopAutoplay"); }, 10000); } .roundabout(
谢谢。您可以在开始时使用回调。比如:
function stopRoundaboutAfterAWhile() {
setTimeout(function() {
.roundabout("stopAutoplay");
}, 10000);
}
.roundabout(options, stopRoundaboutAfterAWhile)
我的解决方案是在页面准备就绪时调用autoplay,并与setTimeout混合使用 另外,我在随机数秒内停止了自动播放,并将div ID保存在localStorage上
$(window).load(function() {
$('ul').roundabout();
$('ul').roundabout('startAutoplay');
var tempo = Math.floor(Math.random()*(10000-5000+1))+5000;
setTimeout(function(){
$('ul').roundabout('stopAutoplay');
}, tempo);
setTimeout(function(){
console.log($('.roundabout-in-focus').attr('id'));
window.localStorage.setItem('vilao',$('.roundabout-in-focus').attr('id'));
}, tempo + 1000);
});