I have an interface that makes heavy use of the jQuery slideUp and slideDown effect to expand items in a tri-state kind of way.
onmouseover: function() {
this.find('.details', this).slideDown();
},
onmouseout: function() {
this.find('.details', this).slideUp();
}
However, when the user quickly moves the mouse over these interface elements the animations can't keep up and the items will be sliding up and down long after the mouse has left the interface area.
Is there a way to cancel all the queued-up slide animations when the mouse leaves the item's container div?
I believe you should be able to just add a .stop() and it'll take care of that for you:
Generally speaking you want to call
stop()
when starting such an animation:That should be sufficient to avoid long-running animation queues.
You can also use
$.clearQueue()
to globally clear animations that haven't yet begun.Also, if you're setting these on
mouseover()
andmouseout()
it is arguably clearer to simply use thehover()
event instead.In my case, I was also looking for a
.stop()
solution to the up and down extensive animation queue. However, it still didn't solve, because it wasn't smooth, and it was buggy, making it not to slide down anymore.Hence, I came with a solution that is not related to cancel queues, but it might help some of you. The solution is about sliding it down or up just when the animation target is not currently being animated.
It is also much better if you put parameters in
stop()
, just like this:stop(true,true)
...You could do something like the following: http://jsfiddle.net/3o2bsxo6/3/
JavaScript
html:
CSS:
The answer you really want is a combination of all the other three answers.
You want the
true
s in the stop because these clear the pending animation queues. If you dont use these, you'll find moving the mouse quickly and repeatedly across the element will produce buggy results.