2017-10-09 199 views
1

我在应用程序中创建了一个简单的加载网格,并在其上添加了一个动画。这个动画似乎适用于除IE11以外的所有浏览器。CSS无限动画无法在IE11中工作

有人可以帮我理解为什么它不工作,如何让它在IE11中工作?

.loading { 
 
    background-color: #ededed; 
 
    height: 12px; 
 
    width: 500px; 
 
    overflow: hidden; 
 
} 
 

 
.animation { 
 
    animation: loading 1.2s linear; 
 
    animation-iteration-count: infinite; 
 
    background-color: #e0e0e0; 
 
    height: 100%; 
 
    left: 0; 
 
    position: relative; 
 
    top: auto; 
 
    width: 300px; 
 
} 
 

 
@keyframes loading { 
 
    from {left: -30rem} 
 
    to {left: calc(100% + 30rem)} 
 
}
<div class="loading"> 
 
    <div class="animation"></div> 
 
</div>

的jsfiddle如果你有兴趣:https://jsfiddle.net/9shufwsL/

+0

可能重复https://stackoverflow.com/questions/34809544/css3-animation-is-not-working-in-ie11-but-works-in - 其他浏览器 – PraveenKumar

+0

尝试这个'动画:加载1.2s无限;' –

+0

@PraveenKumar没有那么多,因为我的问题没有回答任何问题的答案 –

回答

1

显然calc()不会在这方面的工作。

我将中的left的值更改为使用基于百分比的终结点,它在IE11中起作用。

.loading { 
 
    background-color: #ededed; 
 
    height: 12px; 
 
    width: 500px; 
 
    overflow: hidden; 
 
} 
 

 
.animation { 
 
    animation: loading 1.2s linear; 
 
    animation-iteration-count: infinite; 
 
    background-color: #e0e0e0; 
 
    height: 100%; 
 
    left: 0; 
 
    position: relative; 
 
    top: auto; 
 
    width: 300px; 
 
} 
 

 
@keyframes loading { 
 
    from {left: -30rem} 
 
    to {left: 110%} 
 
}
<div class="loading"> 
 
    <div class="animation"></div> 
 
</div>

+0

calc在IE10 + http:// caniuse中很好。 com /#search = calc – Rob

+0

@Rob,所以我们会想,但是在'calc()'在'@keyframes'内的这种特殊情况下它不起作用。搜索IE11钙缺陷返回许多命中。去图... – jfeferman

+1

在别处简要阅读了评论之后,我怀疑在关键帧中使用'calc()'是否有意义,但是我没有给它任何想法。似乎关键帧应该做计算,'calc()'不应该被使用。 – Rob

1

calc()在IE浏览器不工作,你可以改变@keyframes到:

@keyframes loading { 
    from {left: -30rem} 
    to {left: 30rem} 
} 

你可以使用-moz-calc和它的工作,但说实话不是最好的事。

你的关键帧看起来像这样:

@keyframes loading { 
    from {left: -30rem} 
    to {left: -moz-calc(100% + 30rem)} 
} 
+0

在IE11和Edge中测试了Jesse的代码,两者都不适合我。但它确实符合正确答案的代码和我的答案的代码片段。 – Rob

+0

Thx for Page-Link Rob,我只是因为它是IE¯\ _(ツ)_ /¯ – Tibix