<head> |
| <TITLE></TITLE> |
| <script> |
| <!----------소스 여기부터 --------------> |
|
|
| var x,y |
| var marginbottom |
| var marginleft=0 |
| var margintop=0 |
| var marginright |
|
|
| var tempo=10 |
|
|
| var stepx=5 |
| var stepy=5 |
| var timer |
|
|
| function setValues() { |
| var firsttimer= setTimeout("setValues2()",2000) |
| } |
|
|
| function setValues2() { |
| if (document.all) { |
| marginbottom = document.body.clientHeight-50 |
| marginright = document.body.clientWidth-50 |
| document.all.ball1.style.posLeft=10 |
| document.all.ball1.style.posTop=10 |
| moveball() |
| } |
| |
| if (document.layers) { |
| marginbottom = window.innerHeight-10 |
| marginright = window.innerWidth-10 |
| document.ball1.left=10 |
| document.ball1.top=10 |
| moveball() |
| } |
| } |
|
|
| function randommaker(range) { |
| rand=Math.floor(range*Math.random()) |
| return rand |
| } |
|
|
| function moveball() { |
| if (document.all) { |
| checkposition() |
| document.all.ball1.style.posLeft+=stepx |
| document.all.ball1.style.posTop+=stepy |
| timer=setTimeout("moveball()",tempo) |
| } |
| if (document.layers) { |
| checkposition() |
| document.ball1.left+=stepx |
| document.ball1.top+=stepy |
| timer=setTimeout("moveball()",tempo) |
| } |
| } |
|
|
| function checkposition() { |
| if (document.all) { |
| if (document.all.ball1.style.posLeft>=marginright) { |
| stepx=(stepx+randommaker(2))*-1 |
| document.all.ball1.style.posLeft-=10 |
| } |
| if (document.all.ball1.style.posLeft<=marginleft) { |
| stepx=(stepx+randommaker(2))*-1 |
| document.all.ball1.style.posLeft+=10 |
| } |
| if (document.all.ball1.style.posTop>=marginbottom) { |
| stepy=(stepy+randommaker(2))*-1 |
| document.all.ball1.style.posTop-=10 |
| } |
| if (document.all.ball1.style.posTop<=margintop) { |
| stepy=(stepy+randommaker(2))*-1 |
| document.all.ball1.style.posTop+=10 |
| } |
| } |
| if (document.layers) { |
| if (document.ball1.left>=marginright) { |
| stepx=(stepx+randommaker(2))*-1 |
| document.ball1.left-=10 |
| } |
| if (document.ball1.left<=marginleft) { |
| stepx=(stepx+randommaker(2))*-1 |
| document.ball1.left+=10 |
| } |
| if (document.ball1.top>=marginbottom) { |
| stepy=(stepy+randommaker(2))*-1 |
| document.ball1.top-=10 |
| } |
| if (document.ball1.top<=margintop) { |
| stepy=(stepy+randommaker(2))*-1 |
| document.ball1.top+=10 |
| } |
| } |
| } |
|
|
|
|
|
|
| // --------------여기까지 -----------> |
| </script> |
|
|
| </head> |