NOOB question... variable for animate value?
I have a variable that I would like to use to use as an animation value in pixels:
var thisAmount = maxScrollIncrements*DISPLAY_WIDTH
$("#image").animate({left:"+=thisAmount", opacity:1.0}, "fast");
So in this case if "thisAmount" = 1200, I want the equvilant of: $("#image开发者_如何学运维").animate({left:"+=1200px", opacity:1.0}, "fast");
I know this is simple but I am not getting it. Thanks in advance.
The value after the colon is just a string, so you should be able to do:
$("#image").animate({left:"+=" + thisAmount + "px", opacity:1.0}, "fast");
(The "px" is optional.)
Just concatenate your variable to the string literal:
$('#image').animate({ left: '+=' + thisAmount, opacity: 1.0 }, 'fast');
精彩评论