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.
- 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
3 Answers
Reset to default 6Try 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条)