jquery的animate方法的参数

时间:2013-06-16 14:38:42

标签: javascript html css

我知道我的语法有些问题。根据我的经验,与python相比,这个javascript似乎有奇怪的语法。为什么这段代码不起作用?

<script>
  function flutter() {
    var random = Math.floor(Math.random()*5);
    var $obj = $('.bird');
    $obj.animate({ top :'-= 0.5px'+random }, 20, flutter);

    } 
</script>

我知道我添加随机的方式是罪魁祸首,但我不知道正确的方法。

2 个答案:

答案 0 :(得分:2)

'+'重载

尝试

$obj.animate({ top :'-=' + (0.5+random) + 'px' }, 20, flutter);

答案 1 :(得分:0)

“$ obj.animate({top:' - = parseInt(0.5px)'+ random},20,flutter);”