开发者

jQuery conditional for opacity?

How do you test for whether a div has opacity = 0?

I have tried:

if (jQuery("#slideshow div#prev").css({opacity: 0})) 
    {
jQuery("#slideshow div#prev").animate({opacity: 1.0}, 500); 
    }

but it seems to fire off the animation even开发者_JS百科 when the opacity is already 1.0?


Use css('opacity'):

if (!jQuery("#slideshow div#prev").css('opacity')) {
    jQuery("#slideshow div#prev").animate({opacity: 1.0}, 500); 
}

This code checks if the return value of .css('opacity') is falsy, if it is, then either the CSS hasn't been set or the value itself is falsy, in which case you would want to proceed and run the animate call.


Correct syntax would be

if (!jQuery("#slideshow div#prev").css('opacity')) 
    {
       jQuery("#slideshow div#prev").animate({opacity: 1.0}, 500); 
    }

css('opacity') would return 0 and if() condition will be become true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜