如何在css中动画后修复圆弧边框上圆弧的位置

时间:2017-07-24 11:00:56

标签: html5 css3

我正在创建一个css设计,我需要在圆形边框上设置弧形动画我在网上找到了一个代码并且几乎没有任何更改它允许我旋转边框但是在旋转后它又回到了我想要的初始位置在动画完成后将其保持在完全相同的位置。这是代码

.circle {
  width: 100px;
  height: 100px;
  position: relative;
}
.circle .border {

  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: transparent;
  border-radius: 50%;
  border-width:10px;
  border-style:solid;
  border-top-color:orange;
  border-left-color:transparent;
  border-bottom-color:transparent;
  border-right-color:transparent;
  -webkit-animation-name: Rotate;
  -webkit-animation-duration: 2s;
  -webkit-animation-iteration-count:1;
  -webkit-animation-timing-function: linear;
}
.play {
  padding: 20px 30px;
  font-size: 56px;
}
.stop {
  font-size: 12px;
  padding: 30px;
  text-align: center;
}
@-webkit-keyframes Rotate {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(45deg);
  }
}
<div class="circle">
  <div class="border"></div>
  <div class="play"><i class="fa fa-play"></i>
  </div>
</div>

<p>
  PS: The icon loading is a bit slow. Wait until it shows up.
</p>

<div class="circle">
  <div class="border"></div>
  <div class="stop">Stop me please</div>
</div>

1 个答案:

答案 0 :(得分:1)

您可以使用:

animation-fill-mode: forwards;

属性

.circle {
  width: 100px;
  height: 100px;
  position: relative;
}
.circle .border {

  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: transparent;
  border-radius: 50%;
  border-width:10px;
  border-style:solid;
  border-top-color:orange;border-left-color:transparent;border-bottom-color:transparent;border-right-color:transparent;
  -webkit-animation-name: Rotate;
  -webkit-animation-duration: 2s;
  -webkit-animation-iteration-count:1;
  -webkit-animation-timing-function: linear;
animation-fill-mode: forwards;
}
.play {
  padding: 20px 30px;
  font-size: 56px;
}
.stop {
  font-size: 12px;
  padding: 30px;
  text-align: center;
}
@-webkit-keyframes Rotate {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(45deg);
  }
}
<div class="circle">
  <div class="border"></div>
  <div class="play"><i class="fa fa-play"></i>
  </div>
</div>

<p>
  PS: The icon loading is a bit slow. Wait until it shows up.
</p>

<div class="circle">
  <div class="border"></div>
  <div class="stop">Stop me please</div>
</div>