0

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 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

Just concatenate your variable to the string literal:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.