IE 10 & 11 make fixed backgrounds jump when scrolling with mouse wheel

前端 未结 6 1056
不知归路
不知归路 2020-12-02 16:45

When you scroll with the mouse wheel in Windows 8 the fixed background image bounces around like crazy. This only affects IE 10 and IE 11. This affects elements with p

相关标签:
6条回答
  • 2020-12-02 17:08

    I know it is a bit late for an answer but I've had the same problem and was able to fix it by adding these attributes to my css file

    html{
        overflow: hidden;
        height: 100%;    
    }
    body{
        overflow: auto;
        height: 100%;
    }
    

    From the comments:

    This solution stops scroll events from firing on the window, so do be careful if you're using anything that relies on such events firing. codepen.io/anon/pen/VawZEV?editors=1111 ( overflow: hidden, scroll events don't work) codepen.io/anon/pen/PNoYXY?editors=1111 ( overflow: auto, scroll events fire) - Dan Abrey

    So this might cause some problems in your projects. But I don't see another way to workaround this bug in IE.

    0 讨论(0)
  • 2020-12-02 17:12

    try to turn off smooth scrolling option.

    Internet Options - Advenced Tab - Use Smooth Scrolling

    it's like rendering bug.... MS IE team is investigating....

    0 讨论(0)
  • 2020-12-02 17:12

    just simply define body container to relative.

    <style>
        body
        {
            position: relative;
        }
    </style>
    
    0 讨论(0)
  • 2020-12-02 17:13

    Here is a workaround (tested on Windows 8.1):

    Move the "background" CSS property to the BODY element. Currently it is on the DIV element with id="filler". Here is the resulting CSS:

        body {
            font-family: Helvetica, Arial, sans-serif;
            background: #fff url(blue-kitty.jpg) no-repeat fixed center 100px;
        }
    
        #filler {
            text-align: center;
        }
    
        .big-margin {
            margin-top: 500px;
        }
    
    0 讨论(0)
  • 2020-12-02 17:18

    The fix in my case was to simply remove the z-index property from the element that has position:fixed, IE then stopped the strange flickering.

    (disabling smooth scrolling on IE options worked while having he z-index property but that's not a solution since users would most likely have it on by default).

    0 讨论(0)
  • 2020-12-02 17:25

    This looks like a z-index bug, try adding z-index: 1.

    Looking into this, I've found the best way to debug is to:

    Create a simple element at the top of the page, e.g.

     <style>#test {position: fixed; background: red; top: 0; left: 0; width: 4em}</style>
     <div id="test">Test</div>
    

    In all the above cases, this works correctly, and the scroll is smooth. So this proves it can be done! Now slowly add your properties back in, until you are able to get the element with position fixed to work in the context of your site.

    I then found that adding a z-index to the fixed items resolved the issue. (e.g. z-index: 1)

    I also discovered that once a position is set on a child element, the bug presents it's self from that point down/onwards.

    So you need to ensure none of the child elements have a position set, or if they do, you explicitly set a position on each child.

    E.g.

    <!-- Works -->
    <div style="position: fixed;">
        <div>Nice</div>
        <div>Wicked</div>
        <div>Cool</div>
    </div>
    
    <!-- Element with position: relative, experiences the bug -->
    <div style="position: fixed;">
        <div style="position: relative;">sad</div>
        <div>sad</div>
        <div style="position: fixed;">happy</div>
    </div>
    

    It's fixable, but will require some tweaking!

    0 讨论(0)
提交回复
热议问题