2014-02-25 130 views
0

我使用子菜单创建菜单。我试图保持主菜单的悬停风格,只要在子菜单中的鼠标,但只要我从一个链接导航到另一个子菜单中jquery说我跳出子菜单http://jsfiddle.net/7gSaE/子菜单不能正常工作

$(文件)。就绪(函数(E){

$(".menu").mouseenter(function(){ 
    $(this).children("div").slideDown(200); 
}); 

$(".menu").mouseleave(function(){ 
    $(this).children("div").slideUp(200); 
}); 

$(".submenu").mouseenter(function(){ 
$(this).parent("div.menu").children("a:first").css({"color":"#1869b4","background-color":"#ffffff"}); 
}); 

$(".submenu").mouseout(function(){ 
    alert("you are out of the submenu"); 
    $(this).parent("div.menu").children("a:first").css({"color":"#fff","background-color":"transparent"}); 
}); 

}); 
+1

如http:// jsfiddl e.net/arunpjohny/dcWtA/1/? –

+0

只是将mouseout改为mouseleave?谢谢你可以添加它作为答案,所以我可以接受它。 –

回答

1

只要改变鼠标移出到鼠标离开

$(".submenu").mouseleave(function() { 
    $(this).parent("div.menu").children("a:first").css({ 
     "color": "#fff", 
     "background-color": "transparent" 
    }); 
}); 

演示:Fiddle