删除CSS Transitionend事件监听器不起作用 [英] Removing CSS transitionend event listener not working

查看:358
本文介绍了删除CSS Transitionend事件监听器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试删除css transistionend事件侦听器时遇到问题。我可以使用以下方式添加侦听器:

I have a problem trying to remove a css transistionend event listener. I am able to add the listener with:

e.addEventListener('transitionend',function(event) {
    transitionComplete( event.propertyName );
},false);

我正在尝试将其删除,

e.removeEventListener('transitionend',function(event) {
    transitionComplete( event.propertyName );
},false); 

无论我将removeEventListener放在何处,监听都不会被删除。我该怎么办?

No matter where I put the removeEventListener the listen does not get removed. What can I be doing wrong?

我没有为此使用jquery。

I am not using jquery for this.

推荐答案

不要使用匿名函数,而是命名该函数并将其删除放入事件处理程序中。

Don't use an anonymous function, instead name the function and put the removal in the event handler.

var func = function(event) {
   transitionComplete( event.propertyName );
    e.removeEventListener('transitionend',func);
};

e.addEventListener('transitionend',func, false);

这篇关于删除CSS Transitionend事件监听器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆