将动画分配给除特定ul之外的所有无序列表

时间:2014-09-22 19:15:09

标签: javascript jquery html css

我正在使用下面的代码允许我在开始滚动时淡化div,这将分配给我的所有无序列表。有没有办法告诉脚本不要将此函数分配给特定的ul

示例

我希望所有的UL都能在淡入淡出,但是我希望能够参加ul class" test"不要褪色,而是要保持静止。

 tiles = $("ul li").fadeTo(0, 0);
  $(window).scroll(function(d,h) {
  tiles.each(function(i) {
    a = $(this).offset().top + $(this).height();
    b = $(window).scrollTop() + $(window).height();
    if (a < b) $(this).fadeTo(500,1);
 });
 });

2 个答案:

答案 0 :(得分:1)

使用:not()选择器

DEMO

tiles = $("ul li:not(.test)").fadeTo(0, 0);
  $(window).scroll(function(d,h) {
  tiles.each(function(i) {
    a = $(this).offset().top + $(this).height();
    b = $(window).scrollTop() + $(window).height();
    if (a < b) $(this).fadeTo(500,1);
 });
 });

答案 1 :(得分:1)

您可以使用.not()从集合中删除.test类的项目。

tiles = $("ul li").not("ul.test li").fadeTo(0, 0);