如何通过一个事件(hover
,click
..)触发css3动画的重新执行?
在stackoverflow找到一个相关的问题,但是下面给出的答案也不起作用。
http://jsfiddle.net/arunpjohny/8WQcy/1/
animation
必须是infinite
,animation-play-state
才有效。
restart用这种方法挺好:
// retrieve the element
element = document.getElementById("logo");
// reset the transition by...
element.addEventListener("click", function(e) {
e.preventDefault;
// -> removing the class
element.classList.remove("run-animation");
// -> triggering reflow /* The actual magic */
// without this it wouldn't work. Try uncommenting the line and the transition won't be retriggered.
element.offsetWidth = element.offsetWidth;
// -> and re-adding the class
element.classList.add("run-animation");
}, false);
解释:http://www.w3school.com.cn/cssref/pr_animation-play-state.asp
测试:http://www.w3school.com.cn/tiy/c.asp?f=css_animation-play-state&p=...