admin管理员组文章数量:1390659
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':30})
) {
$('.container')
.fadeOut('slow');
}
});
});
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':30})
) {
$('.container')
.fadeOut('slow');
}
});
});
Share
Improve this question
edited Dec 20, 2010 at 1:58
Peter Mortensen
31.6k22 gold badges110 silver badges133 bronze badges
asked Dec 11, 2009 at 19:30
ExodusNicholasExodusNicholas
1,6445 gold badges16 silver badges18 bronze badges
3 Answers
Reset to default 9$('.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');
}
});
});
本文标签: javascriptHow do I get this ifstatement with jQuery css to workStack Overflow
版权声明:本文标题:javascript - How do I get this if-statement with jQuery .css to work? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744577651a2613725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论