2017-02-05 5 views
0
$(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);   
}); 

}; 

http://codepen.io/anush2209/pen/JEZOaG

この遅く作るのですか。私はそれを変更して、それがより遅くなるようにしたい。スピードモディファイアを追加する方法や、一般的な速度範囲を制御するために値を入力する方法がありますか?は、どのように私はこのプロジェクトへのリンクである

+0

私はあなたが(質問に便利なタグを追加してください)のjQueryのデフォルトのアニメーション機能を使用していると仮定。あなたは[animate'のドキュメント(http://api.jquery.com/animate/)をよく読んでください。これはStackOverflowのためのものではありません。 –

+0

'animate'ドキュメント – charlietfl

+0

http://codepen.io/anon/pen/EZRbqPを読んでJS部分を見てスピード変数を検索すれば、これを自分自身で把握できますか?そこに行く。次回はドキュメンテーションhttp://api.jquery.com/animate/ – besciualex

答えて

1

animateメソッドの中にパラメータとしてdurationを渡すことができます。

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

CODEPEN

http://codepen.io/alexincarnati/pen/NdzwQE

関連する問題