NOOB问题...动画值的变量?

时间:2010-03-22 17:01:41

标签: jquery jquery-animate

我有一个变量,我想用它作为动画值,以像素为单位:

var thisAmount = maxScrollIncrements*DISPLAY_WIDTH 
$("#image").animate({left:"+=thisAmount", opacity:1.0}, "fast");

所以在这种情况下,如果“thisAmount”= 1200,我想要等于:  $(“#image”)。animate({left:“+ = 1200px”,opacity:1.0},“fast”);

我知道这很简单但我没有得到它。提前谢谢。

2 个答案:

答案 0 :(得分:2)

冒号后面的值只是一个字符串,所以你应该可以这样做:

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

(“px”是可选的。)

答案 1 :(得分:0)

只需将变量连接到字符串文字:

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