PDA

View Full Version : the animation won't stop


snakedevil1
08-10-2002, 12:41 AM
Hi all,
the box that is supposed to move (selector) isn't stopping,i figure its because the condition in gotoplace is always being met. how do i make sure it is not met, so the clearinterval statement will activate?


var whereisbyid=0;
var animation;
var wheretogo;
var whereis;
var way;

function GoTo(id)
{
whereis=parseInt(document.all.selector.offsetLeft);
switch(whereis)
{
case 0:
whereisbyid=1;break;

case 75:
whereisbyid=2;break;

case 150:
whereisbyid=3;break;

case 225:
whereisbyid=4;break;

}
alert("whereisbyid="+whereisbyid+"\nid="+id);
if(whereisbyid>id) {way="left";} else {way="right";}
wheretogo=id*75;
animation=setInterval("GoToPlace();",50);
// starts the animation using 'setinterval', which calls a function every set number of seconds
}


function GoToPlace()
{

if(wheretogo != whereis)
{
if(way=="left") {whereis--; document.all["selector"].style.left=whereis;}
else {whereis++; document.all["selector"].style.left=whereis;}
// adds the objects position by 1
}
else clearInterval(animation)
// clearinterval stops the animation
}