I have main navigation and sub navigation that for reasons of design are in separate DIVs. I would like to show the appropriate sub-nav when a main nav item is hovered, which I can do, but I also want to keep the sub-nav open if the user moves their mouse outside of the main nav item and into the sub-nav area. The last part is the place where I'm getting stuck.
I'm thinking on the hover out I need to do something with setTimeout() and an IF statement, but I have not been able to make any progress in that area. Is that even an approach worth trying?
HTML:
<div id="mnav">
<ul id="buttons">
<li class="one"><a href="#">Main 1</a></li>
<li class="two"><a href="#">Main 2</a></li>
<li class="three"><a href="#">Main 3</a></li>
<li class="four nav-dark"><a href="#">Main 4</a></li>
</ul>
</div> <!-- /mnav -->
<div id="snav">
<ul class="snav-one">
<li><a href="#">Sub 1.1</a></li>
<li><a href="#">Sub 1.2</a></li>
<li><a href="#">Sub 1.3</a></li>
<li><a href="#">Sub 1.4</a></li>
<li><a href="#">Sub 1.5</a></li>
<li><a href="#">Sub 1.6</a></li>
</ul>
<ul class="snav-two">
<li><a href="#">Sub 2.1</a></li>
<li><a href="#">Sub 2.2</a></li>
</ul>
</div> <!-- /snav -->
JS:
$(document).ready(function() {
$("#buttons li.one, #buttons li.two").hover(function(){
var subnav = 'ul.snav-' + $(this).attr('class');
$("#snav").slideDown('fast').addClass("open").find(subnav).show();
}, function(e){
var subnav = 'ul.snav-' + $(this).attr('class');
$("#snav").slideUp('fast').removeClass("open").find(subnav).hide();
});
});