【问题标题】:Excluding more than one class from hover function从悬停功能中排除一个以上的类
【发布时间】:2012-07-03 16:45:37
【问题描述】:

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

$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 () {

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

【问题讨论】:

    标签: jquery function class hover


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多