2017-05-28 84 views
0

我正在嘗試使用JavaScript創建網站。我需要以這種方式對其進行編程,當您打開網站時,您可以直接進入頁面的底部(不點擊任何內容)。這意味着,頁面會自動向下移動。 我該怎麼做到這一點?如何在不使用JavaScript的情況下將頁面移動到頁面底部?

+1

的可能的複製[自動滾動到頁面底部(https://stackoverflow.com/questions/11715646/scroll-自動到了底部的最頁) – jkp

回答

0

使用window.scrollTo()功能

window.scrollTo(0,document.body.scrollHeight); 
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; 
} 

享受:)

相關問題