Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Test if the scroll bar is at the bottom

345 views
Skip to first unread message

bgold12

unread,
Aug 7, 2008, 12:12:01 AM8/7/08
to
How can I test if a vertical scroll bar is at the bottom of the range?
I know that...

document.getElementById('mydiv').scrollHeight

...returns the range, and...

document.getElementById('mydiv').scrollTop

...returns the position of the top of the scroll handle in the range,
but that's not enough information because the scroll handle adds an
arbitrary amount of height. Is there a way to test for the height of
the scroll handle, or is there just a better way to test if the scroll
bar is at the bottom of the range?

Thanks.

David Mark

unread,
Aug 7, 2008, 12:45:15 AM8/7/08
to
On Aug 7, 12:12 am, bgold12 <bgol...@gmail.com> wrote:
> How can I test if a vertical scroll bar is at the bottom of the range?
> I know that...
>
> document.getElementById('mydiv').scrollHeight
>
> ...returns the range, and...
>
> document.getElementById('mydiv').scrollTop
>
> ...returns the position of the top of the scroll handle in the range,
> but that's not enough information because the scroll handle adds an
> arbitrary amount of height. Is there a way to test for the height of

You need the clientHeight property to complete the equation, but it
has nothing to do with the scrollbar dimensions.

bseanvt

unread,
Aug 13, 2008, 4:10:18 PM8/13/08
to
On Aug 7, 12:12 am, bgold12 <bgol...@gmail.com> wrote:

var myDiv = document.getElementById("myElement"); //get the html
element
height = myDiv.scrollHeight; //total height of
div element
position = myDiv.scrollTop; //where the
scrollbar is positioned if overflowing...
scrollbar = myDiv.clientHeight; //the actual
height of scrollbar widget (the blue thingamajiggy)

//to check if the scrollbar is docked at the bottom
//do something like this...
if((height - position) == scrollbar){
alert('scrollbar is docked at the bottom');
}

-bseanvt

bseanvt

unread,
Aug 14, 2008, 4:28:15 PM8/14/08
to

oops... made a mistake... need to add those vars together. here is the
code:

var container = document.getElementById("my_container");
height = container.clientHeight;
scroll = container.scrollHeight;
positon = container.scrollTop;

if((height + position) == scroll){
/* do something here like reposition scrollbar */
container.scrollTop = 123;
}

0 new messages