Test if the scroll bar is at the bottom

B

bgold12

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

David Mark

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

bseanvt

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.

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
 
B

bseanvt

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top