Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animation detect if animating?

Tags:

jquery

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.

like image 646
Jorge Avatar asked Aug 09 '11 07:08

Jorge


People also ask

How can you tell if an element is currently being animated?

When animating elements with jQuery, you can detect if the animation is in progress by using $(':animated').

How to stop animation using jQuery?

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).

Is jQuery used for animation?

With jQuery, you can create custom animations.

What does an easing do jQuery?

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 .


2 Answers

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.

like image 123
Andy Avatar answered Oct 05 '22 22:10

Andy


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.

like image 36
Kokos Avatar answered Oct 05 '22 22:10

Kokos