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!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…