transitionEnd在firefox中不起作用

时间:2015-05-17 09:19:58

标签: javascript css

尽管使用了正确的前缀,但不会触发transitionend事件。

my jsfiddle

JS

var flyingCarElem = document.getElementById("flyingCar");

 // register an event handler 
   // ('transitionEnd' for FireFox, 'webkitTransitionEnd' for webkit) 
       flyingCarElem.addEventListener("transitionEnd",function(){
      // will be called when the transition has finished.
    alert("The car arrived");
     });

CSS

div {
width: 100px;
height: 100px;
background: red;
-webkit-transition: width 2s; /* Safari */
transition: width 2s;
  } 

   div:hover {
width: 300px;
  } 

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

Firefox中的转换结束事件称为

transitionend

而不是

transitionEnd

你的修复应该很容易:

var flyingCarElem = document.getElementById("flyingCar");

 // register an event handler 
   // ('transitionend' for FireFox, 'webkitTransitionEnd' for webkit) 
       flyingCarElem.addEventListener("transitionend",function(){
      // will be called when the transition has finished.
    alert("The car arrived");
   });