javascript - How to check if DOM node is animating in jQuery - Stack Overflow

I have DOM node and click handler and I need to disable the action while animating. How can I check if

I have DOM node and click handler and I need to disable the action while animating. How can I check if element is currently being animated by a jQuery animation?

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

Do I need to set data('play') on that element that will be clear when finished or there is better way.

I have DOM node and click handler and I need to disable the action while animating. How can I check if element is currently being animated by a jQuery animation?

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

Do I need to set data('play') on that element that will be clear when finished or there is better way.

Share Improve this question edited Dec 12, 2020 at 9:24 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Aug 6, 2013 at 12:52 jcubicjcubic 66.7k58 gold badges249 silver badges455 bronze badges 2
  • 2 When you say "animating", are you referring to jQuery animations or to CSS transitions? – Frédéric Hamidi Commented Aug 6, 2013 at 12:53
  • @FrédéricHamidi jQuery animation. – jcubic Commented Aug 6, 2013 at 12:57
Add a ment  | 

3 Answers 3

Reset to default 6

Try using the following:

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

View: animated selector documentation

Demonstration: http://jsfiddle/smerny/tBDL8/1/

Use

$(element).is(":animated");

You can check if an element is animating by using the :animated selector.

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

For more information look at: http://api.jquery./animated-selector/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744252450a4565232.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信