The power of .stop()

A demo by Terry , presented as part of the article, How to .stop() writing bad jQuery animations . He also .


The broken example

Here is a classical example of a bad, stuttering jQuery-powered animation. Of course we can use simple CSS transitions to perform the same effect, but this effect is executed using jQuery's .animate() amd .slideUp() + .slideDown() to illustrate the general issue with animation queues.

It's somewhat broken!

Yikes! Not so pretty, is it? When you run you cursor through the whole menu, you will notice a lot of delayed animations. That is when your jQuery animation queue is bunching up.


Using .stop(true,false)

After chaining jQuery animations after .stop(true,false) , we are ensuring that the animation queue is cleared by the end state is not forced upon the element.

Much better now…

Try the same thing with this navigation menu. You will see that animation queue no longer bunches up like a freeway pile up.


Using .stop(true,true)

After chaining jQuery animations after .stop(true,true) , we are clearing the animation queue and forcing the end state.

Perhaps not as good…

Sometimes, the second boolean, jumpToEnd , might be detrimental to the effect. Use with caution.