2

我写过这样的jquery代码和html:

$("#bottom_images li").mouseenter(function() {          
        $(this).find("span").animate({bottom:0},500);
    }).mouseleave(function(){
        $(this).find("span").animate({bottom:-70},500);
    });


<ul id="bottom_images">
    <li class="img1 img_active"><span>Text</span></a>
    <li class="img2"><span>Text</span></a>
    ....
</ul>

此代码工作正常(它在 li 元素内的 span 上创建 .animate 效果)。

但是对于 .img_active 类的 li 元素,我不需要这种效果。该元素有两个类 img1 和 img_active。我无法创建排除 li.img_active 的选择器。可能, :not 应该使用,但我有语法问题。

4

2 回答 2

2

你是对的,你应该使用not()jQuery 选择器。

$("#bottom_images li:not(.img_active)").mouseenter(function() {          
    $(this).find("span").animate({bottom:0},500);
}).mouseleave(function(){
    $(this).find("span").animate({bottom:-70},500);
});

另外,请阅读文档

:not() Selector

选择与给定选择器不匹配的所有元素。

于 2013-07-16T19:11:53.227 回答
2

改变:

$("#bottom_images li")

$("#bottom_images li:not(.img_active)")
于 2013-07-16T19:12:12.740 回答