IE8 alternative to window.scrollY?

前端 未结 8 907
一向
一向 2020-11-29 06:02

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

8条回答
  •  醉话见心
    2020-11-29 06:07

    Based on Niels' answer, I come up with a slightly more compact solution when just the Y coord is needed:

    function get_scroll_y() {
        return window.pageYOffset || document.body.scrollTop || document.html.scrollTop;
    }
    

提交回复
热议问题