2011-12-06 80 views
0

下面的问题可能会很容易为你们,但我仍然试图让我的头绕过jQuery。jquery下拉菜单

比方说,我有一个按钮。当我将它悬停时,一个div在按钮底部向下滑动,代表一个下拉菜单。当我没有按住按钮时,菜单应该仍然存在,但显然不是,因为当我将鼠标悬停在按钮上时,我将其设置为打开。当我悬停另一个按钮时,如何将菜单保留在那里并将其关闭?

谢谢。

+0

这将是有益的,如果您能提供一些例子你正在使用的代码,以便其他人可能更好地理解你的意思。 – mason81

回答

0
Hi as you are using hover event to show your pull down menu, you can keep your menu visible even you move your cursor from the button and to hide the menu you can use the following code, which runs on your mouse click anywhere else in the document. 

    // for taks sum menus (to remove if user clicks anywhere else) 
    $(document).mouseup(function (e) 
       { 
        var container = $(".submenu"); //menu div class 

        if (!container.is(e.target) // if the target of the click isn't the container... 
         && container.has(e.target).length === 0) // ... nor a descendant of the container 
        { 
         container.hide(); 
        } 
       }); 

I hope this will help you.