jQuery有条件的不透明度?

red*_*ory 1 javascript jquery conditional-statements

你如何测试div是否具有不透明度= 0?

我试过了:

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

但即使不透明度已经是1.0,它似乎也会触发动画?

Jac*_*kin 5

用途css('opacity'):

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

此代码检查的返回值.css('opacity')是falsy,如果是这样,那么无论是CSS尚未设置或本身的价值是falsy,在这种情况下,你想继续和运行animate通话.