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 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

i would say 'Great Minds think alike' but your 84K is slightly intermediating hehe :)
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.
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?
3

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.