简体   繁体   English

javascript计时器上下页面不会转到页面底部

[英]javascript timer page up and down won't go to bottom of page

I have a timer script which scrolls up and down and repositions the page to the top every 10 seconds and back down every 5 seconds. 我有一个计时器脚本,该脚本上下滚动并每10秒将页面重新定位到顶部,然后每5秒向下定位。 My problem is I can't get it to scroll all the way down. 我的问题是我无法使其一直向下滚动。

<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>

How do i get it to scroll all the way down or page down? 我如何使其一直向下滚动或向下翻页?

thanks in advance 提前致谢

I think this is much simpler and achieves what you're looking for: 我认为这要简单得多,并且可以满足您的需求:

function starttime() {
    setTimeout('scrollDown()',5000);
}

function scrollDown() {
    window.scrollto(0, document.body.scrollHeight);
    setTimeout('scrollUp()',5000);
}

function scrollUp() {
    window.scrollto(0,0);
    setTimeout('scrollDown()',5000);
}

window.onload = starttime

The reason your page wouldn't scroll all the way down is probably with your pixel value of 1200. This scrolls the page down 1200px, which may or may not be all the way. 页面无法完全向下滚动的原因可能是像素值1200。这将页面向下滚动1200px,这可能会一直滚动,也可能不会一直滚动。 Heck, your page could be 10000px high or more. 哎呀,您的页面可能高出10000px。 Try setting a limit that you can safely know you're page will never surpass, like 20000, and it should scroll all the way to the bottom. 尝试设置一个限制,您可以放心地知道自己的页面将永远不会超过,例如20000,并且应该一直滚动到底部。 :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM