Simple animation

Way of doing this animation is to use separate variables and incrementsto work out the bounces and direction.




Over 2000+ free Javascript
at JavaScriptBank.com Website

dx=5		//first horizontal direction is left by 5
dy=5		//first vertical direction is down by 5
curX=350	//the original x-coord of object
curY=150	//the original y-coord of object

function Fly(){
curX+=dx			//work out next x-coord
curY+=dy			//work out next y-coord
if(curX==50||curX==600)dx=-dx	//if x-coord is at bound then bounce by changing direction
if(curY==50||curY==400)dy=-dy	//ditto
PutIt("Flyer",curX,curY)	//Put object 'Flyer' at coord curX,curY
}

Cont=setInterval('Fly()',20)	//Continue the moving by setting interval to call the function
Where PutIt(Id,xx,yy) is a function to put object named Id at coords (xx,yy)
function PutIt(ID,dX,dY){
if(Netscape){
document.layers[ID].left=dX
document.layers[ID].top=dY
}
if(MSIE){
document.all[ID].style.left=dX
document.all[ID].style.top=dY
}
if(NS6){
document.getElementById(ID).style.left=dX
document.getElementById(ID).style.top=dY
}
}