开发者

jQuery += a variable help

So开发者_运维百科 I have

VARIABLE = Math.floor(5*Math.random());

Then

.animate({left: '+=VARIABLE'}

but it doesn't work.

In my css my div already has a left attribute. If I do left: newx + 'px' it sends it to the random number I generated, meaning it jumps to the top of the page.


Variables are not interpolated in strings. Try this:

.animate({left: '+='+VARIABLE}


What do you mean by += a variable? You want to increase the current value of the left position? If so you can also fetch the raw number with the .offset() method, increase it, and use it as the new position.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜