jQuery: interrupting fadeIn()/fadeOut()

Viewed 7780

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?

8 Answers

Adding .stop(true,true) prior to the fadeIn will interrupt any current animations and execute the fadeIn immediately.

$('.saved').stop(true, true).fadeIn().delay(400).fadeOut(4000);
Related