Javascript 5秒后自动将页面滚动至div

Javascript 5秒后自动将页面滚动至div,javascript,jquery,scroll,scrollto,scrolltop,Javascript,Jquery,Scroll,Scrollto,Scrolltop,我是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

我是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秒钟自动将页面滚动到#秒。 我尝试了很多方法,但都失败了,没有找到任何合适的方法

谢谢

您可以使用

window.location.hash = '#second';
这将确定焦点。我会让你在计时器解决方案上做些工作


此外,我不鼓励强迫用户关注某个特定的div。这不是一个很好的用户体验实践,可能会导致用户离开您的网站,特别是因为他们可能不理解页面为什么会向上滚动。

在代码末尾使用此选项

$(function () {
    setTimeout(function () { goToSecondTab(); }, 5000);
    function goToSecondTab() {
        window.location.hash = '#second';
    }
});
setTimeout(function(){window.location.hash = '#second';},5000);

注意那些
高度:100%是错误的。

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

$(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
});

将HTML添加到ZZBOV脚本中的此行,以使其在FF中正常工作:

$('html, body').delay(5000) //wait 5 seconds

我试过很多方法
,什么方法?向我们展示您所拥有的。如果用户在5秒钟之前开始自己滚动,会发生什么?你要打断他/她的滚动并开始你自己的滚动吗?这可能会很烦人。一般来说,在x时间后滚动到某个特定部分会导致糟糕的用户体验,因为你不知道用户在这5秒钟内会做什么。也许他们不想看视频,或者他们暂停视频并开始滚动,直到5秒后才被带到目标位置。实际上,也许用按钮会更好。我已经尝试过类似的方法。。mysite.it/js/jquery.scrollTo-1.4.3.1.js“>$(…).scrollTo(#slider,3000);没有任何效果,显然
setInterval
会无限期地重复。我已经把它放在标题中,但没有任何更改。$(function(){setTimeout(goToSecondTab(),5000)function goToSecondTab(){window location.hash='#second});必须将函数传递给
设置超时
,而不是
未定义