我有一个名为heartbounce
的小型CSS3动画,可制作四个图标"反弹"一个接一个地。你可以在这里看到它(注意JSFiddle仅适用于webkit,你需要添加自己的供应商前缀以便在其他浏览器上查看)
http://jsfiddle.net/franhaselden/92euukf0/5/
img:first-child {
-webkit-animation-name: heartbounce;
-webkit-animation-duration: 0.5s;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease;
-webkit-animation-delay: 1s;
}
img:nth-child(2) {
-webkit-animation-name: heartbounce;
-webkit-animation-duration: 0.5s;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease;
-webkit-animation-delay: 1.2s;
}
img:nth-child(3) {
-webkit-animation-name: heartbounce;
-webkit-animation-duration: 0.5s;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease;
-webkit-animation-delay: 1.4s;
}
img:last-child {
-webkit-animation-name: heartbounce;
-webkit-animation-duration: 0.5s;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease;
-webkit-animation-delay: 1.6s;
}
有点长但你明白了。
目前这个动画发生在页面加载时(第一个延迟1秒,然后为其他每个加上.2s)。问题是我想每10秒重复一次。
注意:添加infinite
不起作用,因为它只是以1秒延迟重新启动动画。这不是我之后的解决方案。尝试使用提供的代码并与上面的步骤1-5进行比较,您将看到它没有回答这个问题。
有人知道这种双重包裹动画延迟是否可行?
答案 0 :(得分:1)
function change()
{
document.getElementById('one').style.webkitAnimationName = "heartbounce";
document.getElementById('two').style.webkitAnimationName = "heartbounce";
document.getElementById('three').style.webkitAnimationName = "heartbounce";
document.getElementById('four').style.webkitAnimationName = "heartbounce";
}
setInterval(function(){
document.getElementById('one').style.webkitAnimationName = "none";
document.getElementById('two').style.webkitAnimationName = "none";
document.getElementById('three').style.webkitAnimationName = "none";
document.getElementById('four').style.webkitAnimationName = "none";
setTimeout(function(){change();}, 0);
}, 10000);
希望它有所帮助。