8


我有一个带有以下内容的css3动画:

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

.animated {
-webkit-animation-name: rotate;
-webkit-animation-duration: 2.4s;
-webkit-animation-iteration-count: infinite;
-webkit-transition-timing-function: ease-in-out;
}

它完美无缺,嗯......,我想让它在循环之间等待:
动画开始,动画结束,等待(大约0.5秒)动画开始,动画结束,等待(大约0.5秒) ......

PS:我试过-webkit-animation-delay了,还是不行。

有什么帮助吗?

4

3 回答 3

24

keyframes为您的动画持续时间增加 0.5 秒,然后在您的动画中创建一个不会改变旋转量的额外帧;

@-webkit-keyframes rotate {
    0% {
    -webkit-transform: rotate(0deg);
    }
    83% { /*2.4 / 2.9 = 0.827*/
    -webkit-transform: rotate(360deg);
    }
    100% {
    -webkit-transform: rotate(360deg);
    }
}
.animated {
...
-webkit-animation-duration: 2.9s; /*note the increase*/
...
}

小演示:小链接

于 2012-09-07T11:58:08.400 回答
0

通过javascript在指定时间内禁用元素上的css类可能会解决您的问题。

function delayAnimation () {
    var animatedEl = document.getElementById('whatever');
    animatedEl.className = '';
    setTimeout(function () {
        animatedEl.className = 'animated'
        setTimeout(delayAnimation, 2400);// i see 2.4s is your animation duration
    }, 500)// wait 0.5s
}

希望这可以帮助。

编辑:我更新了这个答案来修复代码。您可以在jsfiddle上看到一个完整的示例。感谢@Fabrice指出代码不起作用。

于 2012-09-07T12:00:51.550 回答
0

您可以使用过渡。例如:

transition: all 0.6s ease-in-out;

在哪里transition-delay:0.6s;

于 2012-09-07T12:33:34.197 回答