簡體   English   中英

jquery的animate方法的參數

[英]argument of animate method of jquery

我知道我的語法有些問題。 根據我的經驗,與python相比,這個javascript似乎有奇怪的語法。 為什么這段代碼不起作用?

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

    } 
</script>

我知道我添加隨機的方式是罪魁禍首,但我不知道正確的方法。

'+'超載

嘗試

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM