How to get maximum document scrolltop value

hjuster picture hjuster · Oct 19, 2012 · Viewed 40.6k times · Source

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

Answer

Timm picture Timm · Oct 19, 2012

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/