从悬停功能中排除多个类

时间:2012-07-03 16:45:37

标签: jquery function class hover

我有以下脚本在我的导航项目上设置背景图像精灵的动画:

$j(function() {
   $j(".menu-item:not(.current-menu-item) .bottom_nav").hover( function () {
      $j(this).animate( {
         backgroundPosition : '0px 35px'}
      , 300); }
   , function () {
      $j(this).animate( {
         backgroundPosition : '0px 0px'}
      , 600); }
   ); 
});

我现在想从悬停脚本中排除第二个类。我尝试在表单中添加它:

$j(".menu-item:not(.current-menu-item, .current-menu-parent) .bottom_nav").hover( function () {

$j(".menu-item:not('.current-menu-item, .current-menu-parent') .bottom_nav").hover( function () {

但两者都打破了悬停脚本。

1 个答案:

答案 0 :(得分:2)

jQuery .not()/:不是选择器documentation -

  

.not()方法最终会为您提供更多可读性   选择而不是将复杂的选择器或变量推送到:not()   选择器过滤器在大多数情况下,这是一个更好的选择。

$j(".menu-item").not(".current-menu-item,.current-menu-parent").find(".bottom_nav").hover()