如何在某些时候停止动画中的CSS滚动?

时间:2018-03-02 13:53:42

标签: html css

我想用8球的形象创造“滚入”效果。我希望这个动画加载到页面加载并结束然后球到达位于中间(旋转滑块)的文本层。

在codepen上我发现了类似的东西,我已经使用并在某些时候取得了成果,但动画无限。问题是,如果球到达文本层时如何实现停止?

这是我到目前为止所得到的:

.circle {
  display: block;
  width: 100px;
  height: 100px;
  background: none;
  border-radius: 50%;
  /* Animation to spin and move the sphere */
  -webkit-animation: spin 1000ms linear infinite, moveLeftToRight 5s linear infinite;
  -moz-animation: spin 1000ms linear infinite, moveLeftToRight 5s linear infinite;
  -ms-animation: spin 1000ms linear infinite, moveLeftToRight 5s linear infinite;
  animation: spin 1000ms linear infinite, moveLeftToRight 5s linear infinite;
  -webkit-transition: all 1s ease;
  transition: all 1s ease;
  position: absolute;
  left: 0;
}


/* Spinning the sphere using key frames */

@-ms-keyframes spin {
  from {
    -ms-transform: rotate(0deg);
  }
  to {
    -ms-transform: rotate(360deg);
  }
}

@-moz-keyframes spin {
  from {
    -moz-transform: rotate(0deg);
  }
  to {
    -moz-transform: rotate(360deg);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@-webkit-keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
  }
}


/* Move sphere from left to right */

@-moz-keyframes moveLeftToRight {
  0% {
    left: -100px;
  }
  50% {
    left: 50%;
  }
}

@-ms-keyframes moveLeftToRight {
  0% {
    left: -50px;
  }
  50% {
    left: 50%;
  }
}

@keyframes moveLeftToRight {
  0% {
    left: -100px;
  }
  50% {
    left: 50%;
  }
}

@-webkit-keyframes moveLeftToRight {
  0% {
    left: -100px;
  }
  50% {
    left: 50%;
  }
}
<img class="circle" src="https://i.imgur.com/1KfVzUa.png" />

1 个答案:

答案 0 :(得分:0)

您需要添加填充模式以冻结动画结束时的动画状态。

-webkit-animation-fill-mode: forwards;

forwards使动画处于最后一帧的状态

backwards将动画留在开头

相关问题