我有 DOM 节点和单击处理程序,我需要在制作动画时禁用该操作。如何检查元素当前是否由 jQuery 动画制作动画?
$('div').on('click', '.item', function() {
if (/* this not animating */) {
animate($(this));
}
});
我是否需要设置data('play')
完成后将清楚的元素或有更好的方法。
我有 DOM 节点和单击处理程序,我需要在制作动画时禁用该操作。如何检查元素当前是否由 jQuery 动画制作动画?
$('div').on('click', '.item', function() {
if (/* this not animating */) {
animate($(this));
}
});
我是否需要设置data('play')
完成后将清楚的元素或有更好的方法。
尝试使用以下内容:
$('div').on('click', '.item', function() {
$this = $(this); // cached so we don't wrap the same jquery object twice
if (!$this.is(':animated')) {
animate($this);
}
});
查看:动画选择器文档
演示:http: //jsfiddle.net/smerny/tBDL8/1/
采用
$(element).is(":animated");
您可以使用:animated
选择器检查元素是否正在动画。
if($(this).is(":animated")) { ... }
有关更多信息,请查看:http ://api.jquery.com/animated-selector/