I am making some plugin and I need to get maximum scrollTop
value of the document. Maximum scrollTop
value is 2001
, but $(document).height()
returns 2668
and $('body')[0].scrollHeight
gives me undefined
.
How to get 2001
through javascript/jquery?!
You can calculate the maximum value of element. scrollLeft with: var maxScrollLeft = element. scrollWidth - element.
scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. 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 .
The scrollTop() method sets or returns the vertical scrollbar position for the selected elements. Tip: When the scrollbar is on the top, the position is 0. When used to return the position: This method returns the vertical position of the scrollbar for the FIRST matched element.
To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.
The code in your comments should work:
$(document).height() - $(window).height()
Here's an example that alerts when you scroll to the maximum scroll position: http://jsfiddle.net/DWn7Z/
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