What I'm trying to do
I have a dropdown menu which I would like to display only when a user hovers over a link, and then disappear when the mouse leaves the menu and link.
What I'm struggling with
I can make the menu visible, but it disappears as soon as the mouse attempts to visit one li.
Code
Please see the jsFiddle at http://jsfiddle.net/u2Ym6/.
Here is a general rundown:
HTML
<div style="position: relative;">
<a href="#" class="bold" id="userName">Welcome back, User</a>
<ul id="userMenu">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
CSS
ul#userMenu {
position:absolute;
padding:10px;
top:100%; left: 0;
z-index:10;
display:none;
}
ul#userMenu li {
list-style:none;
float:left;
margin: 0 auto;
width:100%;
}
jQuery
$(document).ready(function(){
$('a#userName').bind('mouseover',openUserMenu);
$('ul#userMenu').bind('mouseout',closeUserMenu);
});
function openUserMenu(){
$('ul#userMenu').fadeIn(100);
}
function closeUserMenu(){
$('ul#userMenu').fadeOut(250);
}