Bogen er ikke ret hjælpsom når det kommer til forklaringen af, hvad der sker i dette stykke kode, og jeg har lidt svært ved at gennemskue den.... Det jeg dog er kommet frem til er, at der er en div med et stykke tekst i. Når siden bliver loadet, så tror jeg, at balls.gif dukker op og bevæger sig på en eller anden måde...
Nogen der kan hjælpe ?
Kode: Vælg alt
<html>
<head>
<title>Animation</title>
<META charset="utf-8" />
<META name="keywords" content="Test" />
<META name="description" content="Her tester jeg noget javascript" />
<script type="text/javascript">
function ball(bx, by, bxdir, bydir, bid){
this.xpos = bx; this.ypos = by;
this.xdirn = bxdir; this.ydirn = bydir;
nam = "ball"+bid;
s='<div id=ball'+bid+'style="left: 100px; position: absolute; top: 100px;><img src="shoes0.png" border=0></div>';
ducoment.writeln(s);
this.gr = document.all[nam].style; this.setball = setball;
this.moveball = moveball;
}
function setball(bx, by) {
this.xpos = bx; this.ypos = by;
this.gr.left = bx; this.gr.top = by;
}
function moveball() {
this.ypos+=this.ydirm;
if (this.ypos>ymax) {
this.ydirn=-this.ydirn;
} else if (this.ypos<10){
this.ydirn=Math.abs(this.xdirn);
this.xpos+=this.xdirn;
}
if(this.xpos>xmax){
this.xdirn=-this.xdirn;
} else if (this.xpos<10){
this.xdirn=Math.abs(this.xdirn);
this.setball(this.xpos, this.ypos);
}
}
function onMove() {
for (j=1; j<=numberofballs; j++) {
aball[j].moveball();
}
setTimeout("onMove",1)
}
</script>
</head>
<body>
<div id=test2 style="left:140px; position: absolute; top: 110px">A simple animation demo</div>
<script type="text/javascript" >
numberofballs=10;
aball = new Array();
for (j=1; j<=numberofballs; j++) {
xdirRange = (Math.random()*8)-4;
ydirRange = (Math.random()*8)-4;
aball[j] = new ball(12+(Math.random()*400),13+(Math.random()*400),xdirRange,ydirRange,j);
}
xmax=document.body.clientWidth-30;
ymax=document.body.clientHeight-30;
window.onLoad = onMove;
</script>
</body>
</html>