Check if the item is in fadeIn or fadeOut state ("action")

I need to stop (cancel) the current .fadeIn (5000) and start from the same fadeIn from the very beginning as soon as the button is pressed (otherwise the next fadeIn will start only after 5000). How can I check if a div is actively fading and how to cancel it (I suppose I could just .hide ())?

+6
jquery
source share
2 answers

Use .stop() . You do not need to check if fadeIn is fadeIn ; if it is not, stop does not affect.

You still need to hide it. So it will be something like:

 $('selector').stop(true).hide().fadeIn(5000); 
+13
source share

You can simply use .hide() to stop it from fading and instantly hide it.

If you need to find that it disappears without stopping the fading, it becomes more complex.

The easiest way to detect it without changing it is to use .data to set the value for an element that indicates that it is currently disappearing.

Then, if your call is .fade , use a callback that removes this value, for example:

 element.data('fading', true); element.fade(5000, function() { $(this).data('fading', false); }); 

Then you can check if it is really fading out using:

 if(element.data('fading')) 
0
source share

All Articles