I am trying to build a basic drop down menu with jquery. I have one button inside the top nav that when a user hover, a div will slide down below it. Here is the code I have so far:
<script>
$('.rentals-link').mouseenter(function() {
$('.region-drop-down-menu').slideDown();
});
$('.region-drop-down-menu').hover(function() {
$('.region-drop-down-menu').slideDown();
});
$('.region-drop-down-menu').mouseleave(function() {
$('.region-drop-down-menu').slideUp();
});
</script>
The problem with the code though is that I can not figure out how to make the div slide up when the mouse leaves the button area AND also have it slide up when leaving the div area. Any suggestions?
Maybe do
and
So both elements check whether the mousepointer is inside of the other one before closing. Also this gives the user some time to move the cursor (1 second). My jsfiddle fork: http://jsfiddle.net/zkRq2/