For example,
function fnCheckScroll(){ var iNewHeight = oDiv.scrollHeight; var iscrolTop = oDiv.scrollTop; alert("The value of the scrollHeight property is: " + iNewHeight + "px"); alert("The value of the scrollTop property is: " + iscrolTop + "px"); } <div id="oDiv" style="overflow: scroll; height= 100px; width= 250px; text-align: left"> Hello<br> </div>
In IE 8, the value of scrollTop is always: 0 - returns 0 for scrollTop (even after scrolling)?
clientHeight: It returns the height of an HTML element including padding in pixels but does not include margin, border and scrollbar height. scrollHeight: It returns the height of the content enclosed in an html element including padding but not margin, border and scroll bar.
In summary, scrollTop is how much it's currently scrolled, and scrollHeight is the total height, including content scrolled out of view.
scrollTop is deprecated in strict mode.
An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content. When an element's content does not generate a vertical scrollbar, then its scrollTop value is 0 .
Ref: scrollTop, scrollHeight, clientHeight
See the MDC articles, scrollTop and scrollHeight. In summary, scrollTop is how much it's currently scrolled, and scrollHeight is the total height, including content scrolled out of view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With