jQuery: interrupting fadeIn()/fadeOut()

JamesBrownIsDead picture JamesBrownIsDead · Sep 1, 2010 · Viewed 7.5k times · Source

Let's say I've called $element.fadeIn(200). 100 ms later, something happens on that page and I want to interrupt that fade and immediately fadeOut(). How can I do this?

If you call calling $element.fadeIn(200).fadeOut(0), the fadeOut() only happens after the fadeIn() has finished.

Also, is there a way I can examine $element to determine if a fadeIn() or fadeOut() is running? Does $element have any .data() member that changes?

Answer

Andre Schweighofer picture Andre Schweighofer · Sep 7, 2011

stop() will only remove animations that are not executed yet.

use stop(true, true) to interrupt and remove the current animation too!