Is their a way to detect if an element is animating or detect if values of an element is changing?
Because I need to trigger a function if an element is animating. Not onComplete of animate.
When animating elements with jQuery, you can detect if the animation is in progress by using $(':animated').
The jQuery stop() method is used to stop an animation or effect before it is finished. The stop() method works for all jQuery effect functions, including sliding, fading and custom animations. Syntax: $(selector).
With jQuery, you can create custom animations.
An easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing , and one that progresses at a constant pace, called linear .
The following returns true when the selected element is animating:
var isAnimating = $("#someid").is(':animated');
More detail:
http://api.jquery.com/animated-selector/
and/or
http://api.jquery.com/animate/
step: A function to be called after each step of the animation.
A simple way would be adding a global boolean that gets set to true
as soon as the animation starts. Then you add a callback function to the animation that sets it to false
as it finishes.
var running = false;
$('#start').click(function(){
running = true;
$('#target').animate({opacity: 0.5},'slow',function(){
running = false;
});
});
Edit: Oh I guess there's a selector for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With