是否可以使CSS Pie计时器只运行一次?

时间:2018-03-12 16:00:43

标签: css css3 animation svg css-shapes

我使用CSS Pie Timer,我很难让我的饼图加载动画只运行一次。

我想要动画的顺序:

  1. 圈子未显示
  2. 圆圈开始填充边框颜色
  3. 圈子完全填满
  4. 保持填充(并且不重复)
  5. Demo here

    <div class="wrapper">
      <div class="pie spinner"></div>
      <div class="pie filler"></div>
      <div class="mask"></div>
    </div>
    

    帮助将不胜感激!

1 个答案:

答案 0 :(得分:3)

您只需删除animation-iteration-count - infinite并将animation-fill-mode添加为forwards

以下是工作代码

&#13;
&#13;
.wrapper {
  position: relative;
  margin: 40px auto;
  background: white;
}

.wrapper, .wrapper * {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.wrapper {
  width: 250px;
  height: 250px;
}

.wrapper .pie {
  width: 50%;
  height: 100%;
  transform-origin: 100% 50%;
  position: absolute;
  background: #08C;
  border: 5px solid rgba(0,0,0,0.5);
}

.wrapper .spinner {
  border-radius: 100% 0 0 100% / 50% 0 0 50%;
  z-index: 200;
  border-right: none;
  animation: rota 5s linear forwards;
}

.wrapper:hover .spinner,
.wrapper:hover .filler,
.wrapper:hover .mask {
  animation-play-state: running;
}

.wrapper .filler {
  border-radius: 0 100% 100% 0 / 0 50% 50% 0;
  left: 50%;
  opacity: 0;
  z-index: 100;
  animation: opa 5s steps(1, end) forwards reverse;
  border-left: none;
}

.wrapper .mask {
  width: 50%;
  height: 100%;
  position: absolute;
  background: inherit;
  opacity: 1;
  z-index: 300;
  animation: opa 5s steps(1, end) forwards;
}

@keyframes rota {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
@keyframes opa {
  0% {
    opacity: 1;
  }
  50%, 100% {
    opacity: 0;
  }
}
&#13;
<div class="wrapper">
  <div class="pie spinner"></div>
  <div class="pie filler"></div>
  <div class="mask"></div>
</div>
&#13;
&#13;
&#13;