与CSS问题后:最好不要用display:none
和opacity
发挥自己,把它留给jQuery和使用适当的功能fadeIn()
和。
而不是将display:block; float:left;
放在菜单的<li>
元素上,应该使用display:inline-block
。如果你漂浮<li>
s,这会有效地将它们从他们的父容器中撕下来,并使ul的大小保持为零,因此除非明确设置其大小,否则不可能听到事件mouseleave
事件。
代码问题:在hoverIntent插件中,timeout
可能不是您要查找的内容。超时会在一段时间后自动触发out
事件。要延迟悬停效果,请改为使用sensitivity
和interval
。检查出documentation page。
如果您应用上述修复,则需要的唯一事件是hoverIntent的结束和主导航的mouseleave。 over
事件在当前子菜单中淡入淡出其余部分,当用户悬停导航时,mouseleave
淡入活动子菜单。看看你修改的jsfiddle演示:http://jsfiddle.net/BQuPz/4/
// Hide inactive ones
$('#main-nav > li:not(.current-menu-parent) .sub-menu').hide();
// What to do when hovering over a menu item
$("#main-nav > li").hoverIntent({
over: function(){
// Find the hovered menu's sub-menu
var $submenu = $(this).find('.sub-menu');
// Stop the animation and fade out the other submenus
$('.sub-menu').not($submenu).stop(true,true).fadeOut(260);
// Fade in the current one
$submenu.fadeIn(260);
}
});
// What to do when user leaves the navigation area
$('#main-nav').mouseleave(function(){
// Fade out all inactive submenus
$('#main-nav > li:not(.current-menu-parent) .sub-menu').fadeOut(260);
// Fade in the active one
$('.current-menu-parent .sub-menu').fadeIn(260);
});
这样的问题应该被自动标记尚未另一 - 毫无意义,下拉菜单感创建的 - 谷歌有6,770,000结果“jQuery的下拉菜单” – 2011-05-12 19:44:37
小提琴似乎非功能性 – Dpeif 2014-01-31 17:55:52