How to determine if vertical scroll bar has reached the bottom of the web page?

javascript, scrollbar, window

Solution

When you tell an element to scroll, if its `scrollTop` (or whatever appropriate property) doesn't change, then can't you assume that it has scrolled as far as is capable?

So you can keep track of the old `scrollTop`, tell it to scroll some, and then check to see if it really did it:

function scroller() {
    var old = someElem.scrollTop;
    someElem.scrollTop += 200;
    if (someElem.scrollTop > old) {
        // we still have some scrolling to do...
    } else {
        // we have reached rock bottom
    }
}

Problem

The same question is answered in jQUery but I'm looking for solution without jQuery. How do you know the scroll bar has reached bottom of a page I would like to know how I can determine whether vertical scrollbar has reached the bottom of the web page. I am using `Firefox3.6` I wrote simple Javascript loop to scroll down by 200 pixel and when the scroll bar reached the bottom of the page, I want to stop the loop. The problem is scrollHeight() is returning 1989. And inside loop `scrollTop` is incremented by 200 per iteration. ``` 200 ==> 400 ==> 600 .... 1715 ``` And from 1715, it won't increment so this loop continues forever. Looks like scrollHeight() and scrollTop() is not right way to compare in order to determine the actual position of scrollbar? How can I know when the loop should stop? code: ``` var curWindow = selenium.browserbot.getCurrentWindow(); var scrollTop = curWindow.document.body.scrollTop; alert('scrollHeight==>' + curWindow.document.body.scrollHeight); while(curWindow.document.body.scrollHeight > curWindow.document.body.scrollTop) { scrollTop = curWindow.document.body.scrollTop; if(scrollTop == 0) { if(window.pageYOffset) { //firefox alert('firefox'); scrollTop = window.pageYOffset; } else { //IE alert('IE'); scrollTop = (curWindow.document.body.parentElement) ? curWindow.document.body.parentElement.scrollTop : 0; } } //end outer if alert('current scrollTop ==> ' + scrollTop); alert('take a shot here'); selenium.browserbot.getCurrentWindow().scrollBy(0,200); } //end while ```

Original source

Related problems