Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get maximum document scrolltop value

Tags:

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?!

like image 909
hjuster Avatar asked Oct 18 '12 23:10

hjuster


People also ask

How do you get max scrollLeft value?

You can calculate the maximum value of element. scrollLeft with: var maxScrollLeft = element. scrollWidth - element.

How is scrollTop calculated?

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 .

What does scrollTop return?

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.

How do I get the scroll height of a div?

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.


1 Answers

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/

like image 79
Timm Avatar answered Sep 29 '22 12:09

Timm