当鼠标离开悬停 div 控制菜单时保留下拉菜单的显示
我有一个简单的下拉菜单,使用以下脚本进行控制:
$(document).ready(function () {
$('img.menu_class').hover(function () {
$('.the_menu').slideToggle('medium');
});
});
当鼠标离开“img.menu_class”div时,我无法弄清楚如何继续显示显示的div,即“.the_menu”但保留在“.the_menu”div 中。当鼠标位于这两个 div 中时,需要保留它。
您可以在此处查看当前状态的菜单。只需将鼠标悬停在主导航栏上(目前只是一个图像)即可查看下拉菜单。
有人可以帮忙解决这个问题吗?
谢谢,
尼克
I have a simple drop-down menu that is controlled using the following script:
$(document).ready(function () {
$('img.menu_class').hover(function () {
$('.the_menu').slideToggle('medium');
});
});
I can't work out how to continue to display the div that is revealed, i.e. ".the_menu", when the mouse leaves the 'img.menu_class' div but stays in the ".the_menu" div. It needs to be preserved whilst the mouse is in either of these divs.
You can see the menu in its current state here. Just hover on the main nav bar (it's just an image at the moment) to see the drop-down menu.
Could someone help with this?
Thanks,
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以切换为
mouseenter()
和mouseleave()
,而不是hover()
并稍微更改标记。示例:
HTML:
JS:
此处 是工作代码。
Instead of
hover()
you can switch tomouseenter()
andmouseleave()
and change the markup a bit.Example:
HTML:
JS:
HERE is the working code.
您可以使用
setTimeout
来创建隐藏菜单的延迟:这是一个演示:http ://jsfiddle.net/7vrGu/2/
You can use
setTimeout
to create a delay in hiding the menu:Here is a demo: http://jsfiddle.net/7vrGu/2/
当您仅使用一个参数调用
hover
时,它会运行您在mouseenter
和mouseleave
事件中传入的处理函数。即,它是否将“.the_menu”滑动两次 - 一次当您鼠标悬停
时,一次当您mouseleave
时:http://api.jquery.com/hover/#hover2
您需要调用
hover
带有两个参数,传递一个单独的处理函数来调用mouseleave
。http://api.jquery.com/hover/#hover1
示例:
when you call
hover
with just one argument it runs the handler function you pass in on bothmouseenter
andmouseleave
events. I.e. is it slideToggling ".the_menu" twice - once when youmouseover
, once when youmouseleave
:http://api.jquery.com/hover/#hover2
You need to call
hover
with two arguments, pass a separate handler function to call onmouseleave
.http://api.jquery.com/hover/#hover1
example: