我有一個計時器腳本上下滾動,並將頁面每10秒重新定位到頂部,並每5秒回退一次。我的問題是我無法讓它一直向下滾動。JavaScript的計時器頁面上下不會去頁面底部
<script language="JavaScript" type="text/javascript">
// Configure refresh interval (in seconds)
var refreshinterval=300
// Shall the coundown be displayed inside your status bar? Say "yes" or "no" below:
var displaycountdown="yes"
var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0
function starttime() {
starttime=new Date()
starttime=starttime.getTime()
countdown()
}
function countdown() {
nowtime= new Date()
nowtime=nowtime.getTime()
secondssinceloaded=(nowtime-starttime)/1000
reloadseconds=Math.round(refreshinterval-secondssinceloaded)
if (refreshinterval>=secondssinceloaded) {
var timer=setTimeout("countdown()",1000)
if (displaycountdown=="yes") {
window.status="Page refreshing in "+reloadseconds+ " seconds"
}
if (timer % 5 == 0) {
window.scrollTo(0,1200);
}
if (timer % 10 == 0) {
window.scrollTo(0,0);
}
}
else {
clearTimeout(timer)
window.location.reload(true)
}
}
window.onload=starttime
</script>
如何讓它滾動到下一頁或下一頁?
在此先感謝
您可能需要檢查document.body.scrollHeight是否先存在,如果不存在,則使用screen.height ... if(document.body.scrollHeight){window.scrollto(0,document.body.scrollHeight ); } else {window.scrollto(0,screen.height); } – Fosco 2010-07-07 19:56:30
line window.scrollTo(0,document.body.scrollHeight);解決了我的問題。謝謝! – phill 2010-07-07 20:06:25