开发者

document.body.scrollTop is always 0 in IE even when scrolling

开发者 https://www.devze.com 2022-12-28 11:23 出处:网络
I am displaying the value of document.body.scrollTop in the status barwhile moving the mouse. The value is always 0 in IE. Why开发者_如何学运维 is always 0? Is there another way to get how much the sc

I am displaying the value of document.body.scrollTop in the status bar while moving the mouse. The value is always 0 in IE. Why开发者_如何学运维 is always 0? Is there another way to get how much the scroll bar has moved?


You may want to try this for an older doctype in IE:

var top = (document.documentElement && document.documentElement.scrollTop) || 
              document.body.scrollTop;


this function provides a cross-browser implementation of reading the scroll offset:

function posTop() {
            return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;
        }


Depending on the DOCTYPE, you would have to use document.body.scrollTop or document.documentElement.scrollTop. Have you tried the second one?

You can do something like this:

var scrollTop = document.documentElement ? document.documentElement.scrollTop :
                                           document.body.scrollTop;

I ran into these links while researching your problem:

  • Window size and scrolling (towards the bottom)
  • document.body.scrollTop in IE

This may help you out a little more.

0

精彩评论

暂无评论...
验证码 换一张
取 消