IE8 alternative to window.scrollY?
I'm trying to determine how many pixels down I've scrolled using window.scrollY
. But this isn't supported in IE8. What is the safe, cross-browser alternative?
The cross-browser compatible version for window.scrollY
is document.documentElement.scrollTop
. Please see the 'Notes' section of this piece of Mozilla documentation for a full, detailed workaround in IE8 and before.
As mentioned here, pageYOffset
is another alternative to window.scrollY (note though that this is only IE9+ compatible).
In regard to the link above, check Example 4 for a fully compatible way to get the scroll position (it even accounts for zoom as @adeneo mentioned!) using document.documentElement.scrollTop
and document.documentElement.scrollLeft
.
Here, try out the example for yourself!
If you don't have to use it a lot, just do:
var scroll = window.scrollY //Modern Way (Chrome, Firefox)
|| document.documentElement.scrollTop (Old IE, 6,7,8)
If you're using jQuery, I used $(window).scrollTop() to get the Y position in IE 8. It seemed to work.