var x = document.getElementsByClassName("box");
// Code for Chrome, Safari and Opera
x.addEventListener("webkitAnimationEnd", function(){
console.log("event has ended");
});
// Standard syntax
x.addEventListener("animationend", function(){
console.log("event has ended");
});
.box {
background: red;
position: absolute;
padding: 100px;
}
.box:hover {
animation-name: rotate;
animation-duration: 2s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes rotate {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
<html>
\t
\t <body>
\t
\t <div class="box">
\t </div>
\t </body>
</html>
我试图使用的CSS动画JS,我尝试在控制台日志中显示一条消息,该动画已经结束,但它没有出现,它给了我这个错误:x.addEventListener不是函数 这里是我的代码:
'getElement ** **š返回ByClassName''HTMLCollection'即许多元件** **š。您需要遍历它并为每个元素添加侦听器。 –
另外一个[querySelectorAll','getElementsByClassName'和其他'getElementsBy *'方法返回什么?](http://stackoverflow.com/q/10693845/4642212)。 – Xufox