Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel all queued jQuery slideUp and slideDown animations

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?

like image 686
Candidasa Avatar asked Mar 02 '10 00:03

Candidasa


People also ask

How to stop slideUp jQuery?

The key is to remove . stop() from slideDown() . If it's on there, jQuery will sometimes just jump directly to the target height, "stopping" the animation.

How do you toggle slideUp and slideDown in jQuery?

jQuery slideToggle() Method The slideToggle() method toggles between slideUp() and slideDown() for the selected elements. This method checks the selected elements for visibility. slideDown() is run if an element is hidden. slideUp() is run if an element is visible - This creates a toggle effect.

What is slideUp in jQuery?

The slideUp() is an inbuilt method in jQuery which is used to hide the selected elements. Syntax: $(selector). slideUp(speed); Parameter: It accepts an optional parameter “speed” which specifies the speed of the duration of the effect.


2 Answers

I believe you should be able to just add a .stop() and it'll take care of that for you:

onmouseover: function() { 
this.find('.details', this).stop().slideDown(); 
},
onmouseout: function() { 
this.find('.details', this).stop().slideUp(); 
}
like image 81
Matt Crest Avatar answered Oct 02 '22 14:10

Matt Crest


The answer you really want is a combination of all the other three answers.

$("...").hover(function() {
  $(this).stop(true, true).slideDown();
}, function() {
  $(this).stop(true, true).slideUp();
});

You want the trues 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.

like image 24
Andrew Bullock Avatar answered Oct 02 '22 13:10

Andrew Bullock