jquery删除添加类上悬停 [英] jquery remove add classes on hover

查看:156
本文介绍了jquery删除添加类上悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我发现一个代码,它似乎是工作,但我需要添加一些东西到该代码,以防止它启动,如果我悬停在其子菜单/子菜单元素,但仍然需要启动,当我悬停其他项目或其他项目childern菜单的这是当前脚本

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");     
    });
}); 

所以我当前的活动菜单将有.current-menu-parent或.current-项目。我的子菜单以< ul> class in the parent's< li>类和子菜单类是< ul class =sub-menu>然后继续< li>

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.

推荐答案


  1. 为子级绑定事件处理程序

  2. 让该处理程序调用stopPropagation()

http://api.jquery.com/event.stopPropagation/

这篇关于jquery删除添加类上悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆