繁体   English   中英

jQuery .one多次执行回调函数

[英]jQuery .one is executing callback function several times

我将Animate.css用于带有jQuery n元素的动画。 这是我的代码的一部分。

 $("tr td:nth-child("+columnIndex+")").addClass("animated flip").one('animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd', function(){ $("tr td:nth-child("+columnIndex+")" ).removeClass("highlight"); animationFlag++; alert("Getting called several times"); }); 
我的问题是,增加了animationFlag的回调函数被调用了几次。 实际上,它被称为表中的行数。 有什么办法可以叫它一次。

我找到了解决问题的办法。 我只介绍一个变量“被调用”以跟踪被调用的回调函数。

 var called = false; $("tr td:nth-child("+columnIndex+")" ).addClass("highlight"); $("tr td:nth-child("+columnIndex+")").addClass("animated flip").one('animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd', function(){ if(called==false){ $("tr td:nth-child("+columnIndex+")" ).removeClass("highlight"); animationFlag++; alert('hahhahahaha working'); called = true; }else{ return; } }); 
谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM