Jquery 悬停时不会停留
我正在尝试创建一个下拉列表,它可以工作但不完全,使用此代码
$(document).ready(function(){
$("#zone-bar li em").hover(function() {
var hidden = $(this).parents("li").children("ul").is(":hidden");
$("#zone-bar>ul>li>ul").hide()
$("#zone-bar>ul>li>a").removeClass();
if (hidden) {
$(this)
.parents("li").children("ul").toggle()
.parents("li").children("a").addClass("zoneCur");
}
});
});
我设法使其工作,因此悬停时会出现下拉列表,但当您从下拉列表中选择其中一项时,下拉列表将关闭 任何帮助解决这个问题将非常感谢。
I am trying to create a drop down list i have it working but not fully, using this code
$(document).ready(function(){
$("#zone-bar li em").hover(function() {
var hidden = $(this).parents("li").children("ul").is(":hidden");
$("#zone-bar>ul>li>ul").hide()
$("#zone-bar>ul>li>a").removeClass();
if (hidden) {
$(this)
.parents("li").children("ul").toggle()
.parents("li").children("a").addClass("zoneCur");
}
});
});
I am managed to make it work so on hover the drop down list will appear which is does but when you move to select one of the items from the drop down list the drop down list closes
any help to fix this would be great thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
构建下拉菜单时,您必须确保悬停按钮和子菜单之间没有间隙。如果存在间隙,则会导致其消失,因为您在将鼠标移入子菜单之前将鼠标移出顶部菜单项。您还可以添加轻微的延迟,这样它就不会立即消失。
When building the dropdown menus you have to make sure there are no gaps between the hover button and the sub-menu. If there's a gap it will cause it to disappear because you're mousing out of the top menu item before mousing into the sub menu. You could also add a slight delay so it doesn't go away immediately.