How do I get the scroll position of a document?
Here's how to get the scrollHeight
of an element obtained using a jQuery selector:
$(selector)[0].scrollHeight
If selector
is the id of the element (e.g. elemId
), it is guaranteed that the 0-indexed item of the array will be the element you wish to select, and scrollHeight
will be correct.
$(document).height() //returns window height
$(document).scrollTop() //returns scroll position from top of document
If you are using Jquery 1.6 or above, use prop to access the value.
$(document).prop('scrollHeight')
Previous versions used to get the value from attr but not post 1.6.
document.getElementById("elementID").scrollHeight
$("elementID").scrollHeight