开发者

How do I get this if-statement with jQuery .css to work?

In my jQuery code (I know the if statement isn't jQuery), the CSS property "right" for the class "slider" does NOT equal 30, yet "container" is still fading out on mousedown.. What am I doing wrong?

I want it to be: if the class of slider has a "right" CSS property equal to 30 pixels, then fadeout the container.

$(document).ready(function() {
    $(".slider").mousedown(function() {
        if ($('.slider')
            .css({'right':3开发者_Go百科0})
        ) {
        $('.container')
            .fadeOut('slow');
        }
    });
});


$('.slider').css({'right':30}) returns an array object which always evaluates to true.

You want if ($('.slider').css('right') == "30px") ...


Maybe:

if($('.slider').css('right') == '30'){ ... }

There might be a unit, like px at the end of the value there. Not sure.


$(document).ready(function() {
    $(".slider").mousedown(function() {
        if ($('.slider').css('right') == 30) {
            $('.container').fadeOut('slow');
        }       
    });
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜