Javascript 我该如何让它变慢

Javascript 我该如何让它变慢,javascript,Javascript,这是该项目的链接。我只想把它改慢一点。是否有一种方法可以添加速度修改器或一些我可以输入值来控制一般速度范围的东西。您只需将持续时间作为参数传递到animate方法中即可 $(document).ready(function(){ $("div[name=animate]").each(function(){ animateDiv($(this)); }); }); function makeNewPosition(){ // Get viewport dimensions (remo




这是该项目的链接。我只想把它改慢一点。是否有一种方法可以添加速度修改器或一些我可以输入值来控制一般速度范围的东西。

您只需将持续时间作为参数传递到animate方法中即可

$(document).ready(function(){
$("div[name=animate]").each(function(){
    animateDiv($(this));
});
});

function makeNewPosition(){

// Get viewport dimensions (remove the dimension of the div)
var h = $(window).height() - 50;
var w = $(window).width() - 50;

var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);

return [nh,nw];    

}

function animateDiv(c){
var newq = makeNewPosition();
$(c).animate({ top: newq[0], left: newq[1] }, function(){
  animateDiv(c);        
});

};
CODEPEN


我假设您正在使用jQuery的默认动画功能(请为问题添加有用的标记)。您最好阅读,这不是StackOverflow的目的。如果您阅读
animate
docs查看JS部分并搜索速度变量,您应该自己解决这个问题。好了。下次阅读文档时,请学会写解释问题的普通标题。。。
$(c).animate({ top: newq[0], left: newq[1] }, 3000, function(){
      animateDiv(c);        
    });