3

我有 DOM 节点和单击处理程序,我需要在制作动画时禁用该操作。如何检查元素当前是否由 jQuery 动画制作动画?

$('div').on('click', '.item', function() {
    if (/* this not animating */) {
        animate($(this));
    }
});

我是否需要设置data('play')完成后将清楚的元素或有更好的方法。

4

3 回答 3

6

尝试使用以下内容:

$('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/

于 2013-08-06T12:54:17.250 回答
5

采用

$(element).is(":animated");
于 2013-08-06T12:54:08.293 回答
1

您可以使用:animated选择器检查元素是否正在动画。

if($(this).is(":animated")) { ... }

有关更多信息,请查看:http ://api.jquery.com/animated-selector/

于 2013-08-06T12:55:13.173 回答