5秒后自动滚动页面到div

2024-02-14

我是 javascript 新手,现在我正在尝试这样做,如标题所示,我有一个页面,顶部有一个 div,与包含视频的页面一样大,后面是几个部分,例如这:

<div id="first" style="height:100%; width:100%"></div>
<section id="second" style="height:100%; width:100%"></section>
<section id="third" style="height:100%; width:100%"></section>

现在我需要在页面加载后 5 秒才能将页面自动滚动到 #second。 我尝试了很多方法但都失败了并且没有发现任何可以正常工作的方法。

Thanks


我很慷慨,所以这次我只给你代码。

$(window).load(function () {
    //normally you'd wait for document.ready, but you'd likely to want to wait
    //for images to load in case they reflow the page
    $('body').delay(5000) //wait 5 seconds
        .animate({
            //animate jQuery's custom "scrollTop" style
            //grab the value as the offset of #second from the top of the page
            'scrollTop': $('#second').offset().top
        }, 300); //animate over 300ms, change this to however long you want it to animate for
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

5秒后自动滚动页面到div 的相关文章

随机推荐