さて、あなたはの寸法をキャプチャする必要がありますwindow
generate random numbers
<=
次に、height
とwidth
のscreen
(マイナスwidth
/height
のbox
)が必要になります
ボックスにabsolute
位置を与え、ボックスに生成されたものを与えるx
、y
coordinates
次に、タイマーを設定してthis function
再度呼び出します。
:)
$(document).ready(function() {
randoBox = {
width:$("body").width(),
height:$("body").height(),
x:0,
y:0,
el:null,
time:1000,
state:"active",
init: function(){
el = $(document.createElement('div'));
el.attr("style","position:absolute;left:"+this.x+";top:"+this.y+";");
el.html("DVD")
el.height(100);
el.width(100);
$("body").append(el);
},
move:function(){
this.y = Math.random()*this.height+1;
this.x = Math.random()*this.width+1;
el.attr("style","position:absolute;left:"+this.x+";top:"+this.y+";");
},
run:function(state){
if (this.state == "active" || state){
this.move();
setTimeout(function(){this.run()},this.time);
}
}
}
randoBox.init();
randoBox.run(true);
});