6

This is an issue I seem to keep coming across. If for example I have a drop down navigation menu using a jQuery hover() function and I quickly move my mouse cursor over then off the <li> about 10 times, the subnavigation will appear, then disappear 10 times.

Is there any way to prevent this issue from occuring?

Thanks

Gregg B
  • 13,139
  • 6
  • 34
  • 50
Probocop
  • 10,346
  • 28
  • 85
  • 115

4 Answers4

7

Yes, use the stop function !

$(this).stop().animate(...);

Or

$(this).stop().show();
Flipke
  • 971
  • 6
  • 10
4

We use Hoverintent for our menus. Gives a smart delay before animating:

http://cherne.net/brian/resources/jquery.hoverIntent.html

Gregg B
  • 13,139
  • 6
  • 34
  • 50
3

Use the stop() function to clear the animation queue of an element:

$(this).stop(true).show();
Eric
  • 95,302
  • 53
  • 242
  • 374
1

Well you could unbind the event on entry to it, and bind it again on exit. I tend to use semaphore variables when I can not afford re-entry.

Having said that, the hover() event itself is probably not queuing, but the animations themselves. Either note that you have an animation in progress (semaphores) again, and don't issue another, or stop() the animation(s) in progress before continuing.

Orbling
  • 20,413
  • 3
  • 53
  • 64