我设法同步两个导航级别以使用jQuery显示和关闭。我希望用户在两个级别之外移动鼠标以使其效果良好。这似乎只适用于我的导航中的第一个'li'。有什么想法吗?这里是小提琴:同步导航状态
和我的代码:
//Maintain over state for main nav and sub nav
$('#mainNav li').mouseover(function(){
$(this).children("a").removeClass("whiteHighlight");
if($('#mainNav li span').css('display') == "block"){
$(this).children("a").addClass("whiteHighlight");
}
});
//Remove over state for both when exiting sub nav
$('#mainNav li span').mouseout(function(){
if($('#mainNav li span').css('display') == "none"){
$(this).prev().removeClass("whiteHighlight");
}
});
//Remove over state for both when exiting main nav
$('#mainNav li').mouseout(function(){
if($('#mainNav li span').css('display') == "none"){
$(this).children("a").removeClass("whiteHighlight");
}
});
嗨,谢谢你的解释,这是我想达到的。如果你愿意,请随时提供更多关于如何优化我的代码的信息:) – 2013-04-09 19:39:30