[英]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"); });
我找到了解决问题的办法。 我只介绍一个变量“被调用”以跟踪被调用的回调函数。
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.