【问题标题】:Infinite animation using calc is not working in IE11使用 calc 的无限动画在 IE11 中不起作用
【发布时间】:2018-03-20 17:35:21
【问题描述】:

我在我的应用程序中创建了一个简单的加载网格,并在其上添加了动画。这个动画似乎在除 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/

【问题讨论】:

标签: html css css-animations internet-explorer-11


【解决方案1】:

显然calc() 在这种情况下不起作用。

我将keyframes 中的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>

【讨论】:

  • @Rob 所以我们会想,但在calc()@keyframes 内的这种特殊情况下它不起作用。搜索 IE11 calc 错误会返回许多命中。去图...
  • 在简要阅读其他地方的评论后,我怀疑在关键帧中使用calc() 是否有意义,但我没有考虑过。似乎关键帧应该进行计算并且根本不应该使用calc()
【解决方案2】:

calc() 在 IE 中不起作用,您可以将 @keyframes 更改为:

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

您可以使用-moz-calc,它会起作用,但老实说,这不是最好的做法。

您的关键帧如下所示:

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

【讨论】:

  • 感谢 Page-Link Rob,我刚刚在 IE11 和 Edge 中测试了 Jesse 的代码,但两者都不适合我。但它确实适用于正确答案的代码和我的答案的代码 sn-ps。
猜你喜欢
  • 2017-07-11
  • 1970-01-01
  • 1970-01-01
  • 2016-08-13
  • 2019-09-21
  • 2016-10-27
  • 2017-05-24
  • 1970-01-01
  • 2015-09-18
相关资源
最近更新 更多