CSS动画rotate3d在Safari中不起作用

时间:2018-09-29 19:08:59

标签: html css safari css-animations css-transforms

无论尝试如何,都无法使此动画在Safari 12中正常工作。我已经尝试了供应商前缀和所有前缀,但无济于事。

它在Chrome中正常运行。有人有什么想法吗?

<div class="spinners"></div>

这是CSS:

@keyframes spinx {
  0% {
    transform: rotate3d(0, 1, 1, 360deg);
  }
  100% {
    transform: rotate3d(0, 0, 0, 360deg);
  }
}
.spinners {
  display: block;
  width: 100%;
  height: 4rem;
  overflow: hidden;
  position: relative;
}
.spinners:before, .spinners:after {
  content: "";
  width: 4rem;
  height: 4rem;
  border: 3px solid red;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -2rem 0 0 -2rem;
  display: block;
  transform-origin: 50% 50% 0;
}
.spinners:before {
  animation: spinx 2s infinite linear;
}
.spinners:after {
  border-color: blue;
  animation: spinx 4s infinite linear alternate;
}

这是一个演示: https://codepen.io/Skinner927/pen/vVEdag

1 个答案:

答案 0 :(得分:1)

似乎Safari和Firefox都无法识别两个关键帧之间的变化。为了解决这个问题,您可以使用一个中间关键帧:

50% {
  transform: rotate3d(0, 1, 1, 180deg);
}

演示:

@keyframes spinx {
  0% {
    transform: rotate3d(0, 1, 1, 360deg);
  }
  50% {
    transform: rotate3d(0, 1, 1, 180deg);
  }
  100% {
    transform: rotate3d(0, 0, 0, 0);
  }
}

.spinners {
  display: block;
  width: 100%;
  height: 4rem;
  overflow: hidden;
  position: relative;
}

.spinners:before,
.spinners:after {
  content: "";
  width: 4rem;
  height: 4rem;
  border: 3px solid red;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -2rem 0 0 -2rem;
  display: block;
  transform-origin: 50% 50% 0;
}

.spinners:before {
  animation: spinx 2s infinite linear;
}

.spinners:after {
  border-color: blue;
  animation: spinx 4s infinite linear alternate;
}
<div class="box">
  <div class="spinners"></div>
</div>