我正在尝试使用JavaScript创建网站。我需要以这样的方式编程,当你打开网站时,你直接到达页面的底部(没有点击任何东西)。这意味着,页面会自动向下移动。 我怎么能这样做?
答案 0 :(得分:0)
使用window.scrollTo()
功能
window.scrollTo(0,document.body.scrollHeight);
答案 1 :(得分:0)
这是一个很好的答案: how to automatically scroll down a html page?
包括现场演示:http://jsfiddle.net/ThinkingStiff/DG8yR/
脚本:
function top() {
document.getElementById( 'top' ).scrollIntoView();
};
function bottom() {
document.getElementById( 'bottom' ).scrollIntoView();
window.setTimeout( function () { top(); }, 2000 );
};
bottom();
HTML:
<div id="top">top</div>
<div id="bottom">bottom</div>
CSS:
#top {
border: 1px solid black;
height: 3000px;
}
#bottom {
border: 1px solid red;
}
享受:)