tags:

views:

30

answers:

2

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.

+2  A: 

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

JacobM
A: 

Just concatenate your variable to the string literal:

    $('#image').animate({ left: '+=' + thisAmount, opacity: 1.0 }, 'fast');
bobthabuilda