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...
}
});