ScrollTop not working in IE

前端 未结 5 830
自闭症患者
自闭症患者 2020-12-19 00:37

Anyone have any ideas why scrollTop isn\'t working in IE?

It works in Chrome fine, and I don\'t know about firefox. (The idea of this script is to have an autoscroll

相关标签:
5条回答
  • 2020-12-19 01:03

    Try:

    document.documentElement.scrollTop = x // where x is some integer
    
    0 讨论(0)
  • 2020-12-19 01:08

    Solution for EDGE needs to set scrollTop on scrollingElement document property:

    document.scrollingElement.scrollTop= x; // x is integer value
    

    But you have to ensure, that CSS on HTML element has set overflow to default value (visible):

    html {
        overflow: visible;
    }
    
    0 讨论(0)
  • 2020-12-19 01:09

    The reason things like this don't work on one browser or another is usually due to something like:

    window.document.body.scrollTop++;
    

    You can't just do that because some browsers have that value as a string, e.g. "5px" and some have it as a number.

    0 讨论(0)
  • 2020-12-19 01:13

    Try this

    window.scroll(0,0) //x-axis, y-axis

    0 讨论(0)
  • 2020-12-19 01:18

    If you need it to work in IE and Edge:

    document.body.scrollTop = x
    
    0 讨论(0)
提交回复
热议问题