IE 10 & 11 make fixed backgrounds jump when scroll

2019-01-13 12:35发布

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 position:fixed as well. Is there a prevent it to happen in IE 10 and 11?

Here is an example with a fixed background-image:

http://www.catcubed.com/test/bg-img-fixed.html

6条回答
SAY GOODBYE
2楼-- · 2019-01-13 12:39

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!

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-13 12:42

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.

查看更多
Fickle 薄情
4楼-- · 2019-01-13 12:42

try to turn off smooth scrolling option.

Internet Options - Advenced Tab - Use Smooth Scrolling

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

查看更多
混吃等死
5楼-- · 2019-01-13 12:48

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).

查看更多
Ridiculous、
6楼-- · 2019-01-13 12:49

just simply define body container to relative.

<style>
    body
    {
        position: relative;
    }
</style>
查看更多
来,给爷笑一个
7楼-- · 2019-01-13 12:58

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;
    }
查看更多
登录 后发表回答