jQuery Drop Down Hover Menu

前端 未结 7 963
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 06:44

I\'m new to jQuery, I was hoping you guys could help me. I\'m trying to make a hover dropdown menu, but it\'s extremely buggy. Can you help me clean up my Javascript? Loo

7条回答
  •  Happy的楠姐
    2020-12-29 07:35

    For anyone who finds this in the future Aram's answer can be shortened with .slideToggle() to handle both up and down.

    Here's the modified fiddle

    http://jsfiddle.net/4jxph/2009/

    If you have a sub-menu set to display: none; it will trigger it also, so what you'll want to do is set it to block, then add something like this

    var subMenu = $('li.hoverli > ul > li');
    
    subMenu.hover(function () {
                $(this).find("ul").slideToggle(200);
            });
    

    And place it right below your first slideToggle. Why don't I just show you?

    $(document).ready(function () {
        $(".hoverli").hover(function () {
         $(this).find('ul').slideToggle('medium');
        });
    
        var subMenu = $('li.hoverli > ul > li');
    
        subMenu.hover(function () {
          $(this).find("ul").slideToggle(200);
        });
    });
    

提交回复
热议问题