ページ内をランダムに移動する div があります。
divを「矢印」のような画像に置き換えます。これで、ランダムに移動し、正しい方向を指し(移動時に回転角度を変更します)、常に上を指すとは限りません。
移動時に角度を回転させると思いますが、古い点と新しい点の間の角度を計算する方法がわかりません。
前もって感謝します!!!
これを試して
$(document).ready(function(){
animateIMG();
});
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 animateIMG(){
var newq = makeNewPosition();
$('img').animate({ top: newq[0], left: newq[1] }, function(){
animateIMG();
});
};