admin管理员组文章数量:1415484
I'd like to create an if - else condition system which allows scrolling up only when the top margin is different than 0. I'll use the .animate action in jquery to create an animation.
$('#up-arrow a').click(function(){
if('#slider'.css(margin-top)!='0px')
$('#slider').animate({'margin-top':'+=320px'});
else
Can someone please correct this for me? It works without the if, but after I added the if-else it does nothing.
I'd like to create an if - else condition system which allows scrolling up only when the top margin is different than 0. I'll use the .animate action in jquery to create an animation.
$('#up-arrow a').click(function(){
if('#slider'.css(margin-top)!='0px')
$('#slider').animate({'margin-top':'+=320px'});
else
Can someone please correct this for me? It works without the if, but after I added the if-else it does nothing.
Share Improve this question asked Nov 28, 2011 at 19:10 Alex G.Alex G. 2772 gold badges5 silver badges14 bronze badges 1-
1
Hint:
if('#slider'.css(margin-top)!='0px')
– jsalonen Commented Nov 28, 2011 at 19:12
2 Answers
Reset to default 5Instead of this
if('#slider'.css(margin-top)!='0px')
Try this
if($('#slider').css("margin-top")!='0px')
If else statements require curly braces. If statements with a single expression may be written without curly braces but this practice is usually advised against.
Try this:
$('#up-arrow a').click(function(){
if($('#slider').css("margin-top")!='0px') {
$('#slider').animate({'margin-top':'+=320px'});
} else {
//whatever you want to do here...
}
});
本文标签: javascriptIfstatement with div margintop as conditionStack Overflow
版权声明:本文标题:javascript - If-statement with div margin-top as condition? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745232622a2648893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论