10秒后停止自动播放-环岛

stopping auto play after 10 seconds - RoundAbout

本文关键字:自动播放 -环岛 10秒      更新时间:2023-09-26

我正在使用RoundAbout插件用AutoPlay制作幻灯片。它工作正常,但我想在几秒钟后停止自动播放。我阅读了文档并尝试了"autoplayDuration",但它并不像看上去的那样:P

那么,有什么提示或暗示我该怎么做呢?谢谢

您应该在启动时使用回调。类似于:

function stopRoundaboutAfterAWhile() {
    setTimeout(function() {
        .roundabout("stopAutoplay");
    }, 10000);
}
.roundabout(options, stopRoundaboutAfterAWhile)

我的解决方案是在页面准备就绪时调用自动播放,并与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);
    });