开发者

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

开发者 https://www.devze.com 2022-12-13 16:56 出处:网络
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 w

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

精彩评论

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