javascript – 如何检查DOM节点是否在jQuery中动画

前端之家收集整理的这篇文章主要介绍了javascript – 如何检查DOM节点是否在jQuery中动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有DOM节点和点击处理程序,我需要在动画时禁用该操作.如何检查元素当前是否正在通过jQuery动画进行动画处理?

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

我是否需要在该元素上设置数据(‘play’),这些数据在完成时会更清楚,或者有更好的方法.

解决方法

尝试使用以下内容

$('div').on('click',function() {
    $this = $(this); // cached so we don't wrap the same jquery object twice
    if (!$this.is(':animated')) {
        animate($this);
    }
});

查看:animated selector documentation

示范:http://jsfiddle.net/smerny/tBDL8/1/

猜你在找的jQuery相关文章