views:

439

answers:

4

I have a setup as described in this question which works perfectly. Essentially a drop down menu grows when you move your mouse over it to expose more options.

There is, however, a small issue. If you move the mouse outside of the #dropdown div and then back in again quickly it constantly fires the mouseenter and mouseleave events causing a never ending cycle of flickering. How can I get around it?

Here is my current jQuery code

$("#dropdown").hover(function() { 
        $(this).stop(true,true).fadeTo('fast',1);
        $("#options").stop(true,true).slideDown();
    }, function() { 
        $(this).stop(true,true).fadeTo('fast',0.1);
        $("#options").stop(true,true).slideUp();
    }
);

And current HTML code

<div id="dropdown">
    <div id="optionsPeek">Options</div>
    <div id="options">
        <!-- Links here -->
    </div>
</div>

dropdown is visible by default (10% opacity), optionspeek is always visible and once you hover over it, the options div slides down and the links inside it become visible.

A: 

The best way I've found to deal with such issues is to use the HoverIntent plug-in. It was designed to prevent the flicker problems you're having.

GSto
+1  A: 

What if you add a delay() to the fadeout? For example 1-2 seconds. That way you can move your mouse away and back onto the dropdown without causing any animations.

http://api.jquery.com/delay/

Alec
This looked good but unfortunately it doesn't seem to work with `stop()`
Chris
I got this working perfectly and it now looks great, thanks
Chris
+1  A: 

I don't seem to be getting the flickering you mentioned, but then again - I did create the markup because yours wasn't available.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">
$(document).ready(function() {
    $("#dropdown").hover(function() { 
        $(this).stop(true,true).fadeTo('fast',1);
        $("#options").stop(true,true).slideDown();
    }, function() { 
        $(this).stop(true,true).fadeTo('fast',0.1);
        $("#options").stop(true,true).slideUp();
    }
);
});
</script>
</head>
<body>
<div id="dropdown" style="width: 300px; height: 150px; border: 1px solid black;">DROPDOWN</div>
<div id="options" style="width: 300px; height: 150px; border: 1px solid black;">OPTIONS</div>

</body>
</html>
Neurofluxation
A: 

use:

overflow: hidden;

josh