I’m using jQuery to toggle the visibility of a <div> using the jQuery toggle method. The toggle is fired on the mouseenter and mouseleave event, thus creating the effect of the div to fold out on mouseenter and fold in on mouseleave. Problem is, if the user drags the mouse over the <div> a few times and then leaves the <div>, the div will toggle in and out several times. This can happen if the user accidentally moves around the mouse pointer in the <div> are. Do anyone have any idea on how I can avoid this behavior?
Thanx!
Two things:
If you’re going to use both
mouseenterandmouseleaveI’d suggest using thehover()function; andWhen using triggered animations it’s a good habit to get into to use the
stop()method.So:
Note: replace
"..."with the appropriate selector for what you’re toggling and use the appropriate effect (I’m using fade here). Also,thisin an event handler refers to the source of the event.