In Javascript window.pageYOffset
and document.documentElement.scrollTop
both measures the distance of an window top to its topmost visible content in pixel. Are they both same or am I missing something?
Trust window.pageYOffset
is not supported for IE < 9 but if assuming IE >8 then
scrollTop will be useful when you are in a particular page and want the value relative to that page where as window. pageYOffset only applied to whole html page. Otherwise like krish has mentioned, results from these two are basically the same.
The read-only Window property pageYOffset is an alias for scrollY ; as such, it returns the number of pixels the document is currently scrolled along the vertical axis (that is, up or down) with a value of 0.0, indicating that the top edge of the Document is currently aligned with the top edge of the window's content ...
Both window.pageYOffset and document.documentElement.scrollTop returns the same result in all the cases.
Yes, window.pageYOffset is not supported below IE 9.
scrollTop() method also can be used to get the vertical scrollbar position of the specific element.
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