如何自动向下滚动HTML页面?

Ham*_*one 29 html javascript css height scroll

我试图在主页之后开始每页大约500px,类似于这个网站:http://unionstationdenver.com/

您会注意到在主页后查看页面时,您会自动向下滚动而不另行通知,但您可以向上滚动以再次调整特色滑块.

我玩过scrolledHeight,但我不认为这就是我需要的????

基本上我有一个特色部分位于我的所有内容页面之上,但在向上滚动之前,您不应该看到此部分.有帮助吗?

Thi*_*iff 43

你可以用.scrollIntoView()它.它会将特定元素带入视口.

例:

document.getElementById( 'bottom' ).scrollIntoView();
Run Code Online (Sandbox Code Playgroud)

演示:http://jsfiddle.net/ThinkingStiff/DG8yR/

脚本:

function top() {
    document.getElementById( 'top' ).scrollIntoView();    
};

function bottom() {
    document.getElementById( 'bottom' ).scrollIntoView();
    window.setTimeout( function () { top(); }, 2000 );
};

bottom();
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="top">top</div>
<div id="bottom">bottom</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

#top {
    border: 1px solid black;
    height: 3000px;
}

#bottom {
    border: 1px solid red;
}
Run Code Online (Sandbox Code Playgroud)


Sea*_*ins 2

用于document.scrollTop更改文档的位置。scrollTop将的设为document等于bottom您网站的特色部分的