7

我正在使用 WOW.js 和 animate.css,现在我正在将我的 CSS 运行到 Infinite。我想知道如何让我的课程停止运行 3 秒并重新开始无限?

我的html:

<img src="images/fork.png" class="fork wow rubberBand"  >

我的 CSS 类:

.fork {
    position: absolute;
    top: 38%;
    left: 81%;
    max-width: 110px;
    -webkit-animation-iteration-count: infinite ;
    -webkit-animation-delay: 5s;

}

解决方案可以是 JS 或 CSS3。

4

2 回答 2

19

对于纯 CSS3 动画,在动画的每次迭代之间添加延迟的一种方法是修改关键帧设置,以便它们产生所需的延迟。

在下面的代码片段中,正在执行以下操作:

  • 动画的整个持续时间为 6 秒。为了有延迟,整个持续时间应该是动画实际运行的持续时间+时间延迟。在这里,动画实际上运行了 3s,我们需要 3s 的延迟,所以设置持续时间为 6 秒。
  • 对于动画的前 50%(即 3 秒),没有任何反应,元素基本保持其位置。这给出了应用 3 秒延迟的外观
  • 在接下来的 25% 的动画中(即 1.5 秒),元素使用 .向下移动 50 像素transform: translateY(50px)
  • 对于动画的最后 25%(即最后 1.5 秒),元素向上移动 50px 使用transform: translate(0px)(回到其原始位置)。
  • 整个动画无限次重复,每次迭代都会有 3 秒的延迟。

div{
  height: 100px;
  width: 100px;
  border: 1px solid;
  animation: move 6s infinite forwards;
}
@keyframes move{
  0% { transform: translateY(0px);}
  50% { transform: translateY(0px);}
  75% { transform: translateY(50px);}
  100% { transform: translateY(0px);}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div>Some content</div>


animation-delay属性仅对第一次迭代引入延迟,因此它不能用于在每次迭代之间添加延迟。下面是一个示例片段来说明这一点。

div{
  height: 100px;
  width: 100px;
  border: 1px solid;
  animation: move 6s infinite forwards;
  animation-delay: 3s;
}
@keyframes move{
  0% { transform: translateY(0px);}
  50% { transform: translateY(50px);}
  100% { transform: translateY(0px);}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div>Some content</div>

于 2015-08-26T10:20:10.560 回答
0

像这样

html

<div class="halo halo-robford-animate"></div>

css

body{
  background: black;
}

.halo{
  width: 263px;
  height: 77px;
  background: url('http://i.imgur.com/3M05lmj.png');
}

.halo-robford-animate{
    animation: leaves 0.3s ease-in-out 3s infinite alternate;
    -webkit-animation: leaves 0.3s ease-in-out 3s infinite alternate;
     -moz-animation: leaves 0.3s ease-in-out 3s infinite alternate;
    -o-animation: leaves 0.3s ease-in-out 3s infinite alternate;
}

@-webkit-keyframes leaves {
    0% {
        opacity: 1;
    }

    50% {
      opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

@-moz-keyframes leaves {
    0% {
        opacity: 1;
    }

    50% {
      opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

@-o-keyframes leaves {
    0% {
        opacity: 1;
    }

    50% {
      opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

@keyframes leaves {
   0% {
        opacity: 1;
    }

    50% {
      opacity: 0.5
    }

    100% {
        opacity: 1;
    }
}

jsfiddle

于 2015-08-26T10:20:36.447 回答