0
$(document).ready(function(){

$("li").click(function(){

    if ($(this).hasClass("active") )

          $(this).fadeTo("slow", 1.0); 

    });
});

I have a navigation bar made and am using this code to add a transparency effect on hover:

$(document).ready(function(){
 $(".thumbs").fadeTo("slow", 0.6); 

 $(".thumbs").hover(function(){

    $(this).fadeTo("slow", 1.0); 

    },function(){

    $(this).fadeTo("slow", 0.4); 

    });

});

I'm also using hoverIntent.

The opacity rollover works a treat, but I'd like my "active" page to have 100% opacity, but I can't seem to get it to work..what am I doing wrong?

the link in questions HTML is:

<ul id="navigation">
  <li class="active"><a href="page.htm"></a></li>
</ul>

the nav works perfect minus my "active" class so I think I provided all the necessary code.

4

2 回答 2

1

您不需要 hasClass 测试。你可以换...

$("li").click(function(){
    if ($(this).hasClass("active") )
          $(this).fadeTo("slow", 1.0); 
    });
});

有了这个.....

$("li.active").click(function(){
    $(this).fadeTo("slow", 1.0); 
});
于 2009-12-15T11:18:12.013 回答
0

而不是.click(),你可能想要.each()在这里,但你可以做的比这更简单:)

在页面加载时,您可以使用:not()选择器执行此操作:

$("li:not(.active)").fadeTo("slow", 0.6);

<li>这只会淡出没有class="active"

于 2010-04-17T12:24:42.043 回答