jquery 删除悬停时添加类
好吧,我找到了一个代码,它似乎可以工作,但我需要在该代码中添加一些内容,以防止它在我将鼠标悬停在其子菜单/子菜单元素上时触发,但当我将鼠标悬停在其他项目或其他项目子菜单的这是当前脚本
$(document).ready(function() {
$("#navbar li:hover, #navbar li:sfhover").hover(function(){
$('#navbar .current-menu-parent, #navbar li.current-menu-item').addClass("non-ahover");
},
function(){
$('#navbar li.current-menu-parent, #navbar li.current-menu-item').removeClass("non-ahover");
});
});
所以我当前的活动菜单将具有 .current-menu-parent 或 .current-menu-item。我的子菜单以 < 开头ul>父类 < 内的类力>类和子菜单类是 < ul class="子菜单" >然后继续<力>其项目的类。
所以我的问题是,当我将鼠标悬停在子菜单上时,该子菜单的其中一个项目是当前页面或正在查看的父页面处于活动状态,上面的脚本会触发并导致丑陋,是否有一段代码可以放入其中如果当前子菜单可见,则停止调用的脚本,因此它不应用脚本想要应用的类?
我知道可能有点令人困惑,但如果您需要澄清,请告诉我,我会尽力提供帮助。
Alright so i found a code and it seems to be working but I need to add something to that code to prevent it from firing if I hover over its child menu/sub-menu element but still needs to fire when i hover over other items or other items childern menu's this is the current script
$(document).ready(function() {
$("#navbar li:hover, #navbar li:sfhover").hover(function(){
$('#navbar .current-menu-parent, #navbar li.current-menu-item').addClass("non-ahover");
},
function(){
$('#navbar li.current-menu-parent, #navbar li.current-menu-item').removeClass("non-ahover");
});
});
So my current active menu would have either the .current-menu-parent or .current-menu-item. my sub menu starts with a < ul > class inside of the parent's < li > class and the sub-menus class is < ul class="sub-menu" > then proceeds with < li > classes for its items.
So my problem is when i hover over my sub-menu that is active by one of its items being the current page or by the parent page being viewed the script above fires and causes ugliness is there a snippet of code i can put inside of this script that stop the call if the current sub-menu is visible so it does not apply the class the script wants to apply?
I know might be a little confusing but if you need clarification at all please let me know and i will help as best as i can.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://api.jquery.com/ event.stopPropagation/
http://api.jquery.com/event.stopPropagation/