Firefox中CSS动画效果不佳

时间:2019-02-01 20:02:07

标签: css

我有这样简单的负载指示器

https://jsfiddle.net/tcdLj0f9/

body {
  background: #1e263e;
}

.load {  
  display: flex;
  position: fixed;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
}

.loadersp {
    border: 12px solid #f3f3f3;
    border-top: 12px solid #555!important;
    border-radius: 50%;
    width: 96px;
    height:96px;
    animation: sp-rotate 2s linear infinite;
}
@keyframes sp-rotate {
    0% {
        transform: rotate(0deg)
    }
    to {
        transform: rotate(1turn)
    }
}
<div class="load">
  <div class="loadersp"></div>
</div>
 

它在Chrome浏览器中运行平稳,而在Firefox(使用最新版本)中却无法运行。我知道他们使用不同的渲染引擎,但是我没想到会发生这种事情。

那么有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:1)

这看起来像是Firefox错误。

如果您在position:fixed内的iframe容器中使用动画(例如jsfiddle或SO片段),则动画在Firefox中运行不稳定。在iframe中,它工作正常。

卸下position:fixed修复它在iframe

body {
  background: #1e263e;
}

.load {
  display: flex;
  /* position: fixed; */
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
}

.loadersp {
  border: 12px solid #f3f3f3;
  border-top: 12px solid #555 !important;
  border-radius: 50%;
  width: 96px;
  height: 96px;
  animation: sp-rotate 2s linear infinite;
}

@keyframes sp-rotate {
  0% {
    transform: rotate(0deg)
  }
  to {
    transform: rotate(1turn)
  }
}
<div class="load">
  <div class="loadersp"></div>
</div>