IE8替代window.scrollY? [英] IE8 alternative to window.scrollY?
问题描述
我尝试使用 window.scrollY
来确定我滚动了多少像素。但这在IE8不支持。什么是安全的跨浏览器选项?
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?
推荐答案
窗口的跨浏览器兼容版本。 scrollY
是 document.documentElement.scrollTop
。请参阅本文 Mozilla文档 ,了解IE8及之前的完整详细解决方法。
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.
如此处所述 , pageYOffset
是window.scrollY的另一种替代方法(注意,这只是IE9 +兼容)。
As mentioned here, pageYOffset
is another alternative to window.scrollY (note though that this is only IE9+ compatible).
对于上述链接,请选中示例4 以获得滚动位置的完全兼容方式(甚至将缩放视为@ adeneo提到!)使用 document.documentElement.scrollTop
和 document.documentElement.scrollLeft
。
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
.
这篇关于IE8替代window.scrollY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!