我有一个JQuery导航,单击一个父<li>就可以使用JQuery向下滑动。在第二次点击时,它会将导航向上滑动。我的问题是,我的客户希望如果他点击屏幕上的其他地方,它也会滑动回来,也就是说,只要点击空白区域就会折叠导航。
有什么想法吗?
下面是Jquery:
$('#menu-flag-menu > li > a').click(function(e) {e.preventDefault();});
$("#menu-flag-menu li a").click(function(){
// close all opened sub menus
$("ul", $(this).parent().siblings()).stop(true,true).slideUp();
var ul = $(this).next("ul");
ul.stop(true,true).slideToggle('fast');
});发布于 2012-01-10 22:34:45
这应该是可行的:
$(document).click(function (e) {
// if we click on anything other than the navigation menu
// or it's descendants then slide up the menu
if(e.target.id !== "menu-flag-menu"
&& !$(e.target).closest("#menu-flag-menu").length) {
$(".sub-menu").stop().slideUp();
}
});发布于 2012-01-10 22:37:18
我的建议是尝试使用.mouseenter事件打开菜单,使用mouseleave事件关闭菜单。
https://stackoverflow.com/questions/8804857
复制相似问题