views:

44

answers:

2

Having some issues with my dropdown menu. Code here: http://jsfiddle.net/xY2p6/1/

Something simple I'm just not getting, but as you can see it's not functioning correctly. I'm not sure how to link the hiding of the dropdown to when the user hovers off of the menu link, rather than the actual dropdown.

Any ideas?

+2  A: 

Since your menu is inside the same <li> you can just attach the hover to it directly, like this:

$(function() {
    $(".dropdown").hover(function() {
        $(this).children("div.sub-menu").slideDown(200);
    }, function() {
        $(this).children("div.sub-menu").slideUp(200);
    });
});​

You can give it a try here, or even simpler with .slideToggle(), like this:

$(function() {
    $(".dropdown").hover(function() {
        $(this).children("div.sub-menu").slideToggle(200);
    });
});​

You can give it a try here.

Nick Craver
i would say 'Great Minds think alike' but your 84K is slightly intermediating hehe :)
RobertPitt
Thanks, I knew the solution was simple. I added a .stop() on the second function to get rid of that repeating animation behavior that is so common with this stuff.
dmackerman
Interesting. The slideToggle() solution only works on jsfiddle for some reason. When I put it on the page and hover over the menu link, the menu will drop, but it wont go away unless you hover out and then back onto the menu link?
dmackerman
+1  A: 

Your javascript is slighty messed up.

$(document).ready(function() {
    $(".dropdown").hover(
        function(){
            $(this).children("div.sub-menu").slideDown(200);
        },
        function(){
            $(this).children("div.sub-menu").slideUp(200);
        }
    );
});​

here you go: http://jsfiddle.net/xY2p6/4/

RobertPitt