开发者

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

开发者 https://www.devze.com 2023-01-06 13:29 出处:网络
I have a timer script which scrolls up and down and repositions the page to the top every 10 开发者_JS百科seconds and back down every 5 seconds.My problem is I can\'t get it to scroll all the way down

I have a timer script which scrolls up and down and repositions the page to the top every 10 开发者_JS百科seconds and back down every 5 seconds. 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. Heck, your page could be 10000px high or more. 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. :D

0

精彩评论

暂无评论...
验证码 换一张
取 消