开发者

NOOB question... variable for animate value?

开发者 https://www.devze.com 2022-12-23 23:55 出处:网络
I have a variable that I would like to use to use as an animation value in pixels: var thisAmount = maxScrollIncrements*DISPLAY_WIDTH

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');
0

精彩评论

暂无评论...
验证码 换一张
取 消