问题
I have a css3 animation with the following:
@-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;
}
It works flawlessly, well..., I want to make it wait between the loops:
animation-start, animation-finish, wait(about 0.5s), animation start, animation end, wait(about 0.5s)...
PS: I've tried -webkit-animation-delay
, it does not work.
Any help?
回答1:
Add 0.5 seconds to your animation duration, then create an extra frame in your keyframes
that doesn't change the rotation amount;
@-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*/
...
}
Little demo: little link.
回答2:
You may use a transition. For example:
transition: all 0.6s ease-in-out;
where transition-delay:0.6s;
回答3:
Disabling the css class on element for a specified time by javascript might solve your problem.
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
}
Hope this helps.
Edit : I updated this answer to fix the code. You can see a fully working example on jsfiddle. Thanks to @Fabrice for pointing out the code was not working.
来源:https://stackoverflow.com/questions/12317466/how-make-a-looped-animation-wait-using-css3