Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping animation

Status
Not open for further replies.

bulldog1256

Programmer
Joined
Jul 15, 2005
Messages
1
Location
US
Just started using Javascript and I am using this code:
<script language="javascript">
img1= new Image();
img1.src="header/re20.gif";
img2= new Image();
img2.src="header/re21.gif";
img3= new Image();
img3.src="header/re22.gif";
img4= new Image();
img4.src="header/re23.gif";
img5= new Image();
img5.src="header/re24.gif";
img6= new Image();
img6.src="header/re25.gif";
img7= new Image();
img7.src="header/re26.gif";
img8= new Image();
img8.src="header/re27.gif";
img9= new Image();
img9.src="header/re28.gif";
img10= new Image();
img10.src="header/re29.gif";
img11= new Image();
img11.src="header/re30.gif";
img12= new Image();
img12.src="header/re31.gif";


imgarray = new Array(12);
imgarray[1] = new Image();
imgarray[1].src = "header/re20.gif";
imgarray[2] = new Image();
imgarray[2].src = "header/re21.gif";
imgarray[3] = new Image();
imgarray[3].src = "header/re22.gif";
imgarray[4] = new Image();
imgarray[4].src = "header/re23.gif";
imgarray[5] = new Image();
imgarray[5].src = "header/re24.gif";
imgarray[6] = new Image();
imgarray[6].src = "header/re25.gif";
imgarray[7] = new Image();
imgarray[7].src = "header/re26.gif";
imgarray[8] = new Image();
imgarray[8].src = "header/re27.gif";
imgarray[9] = new Image();
imgarray[9].src = "header/re28.gif";
imgarray[10] = new Image();
imgarray[10].src = "header/re29.gif";
imgarray[11] = new Image();
imgarray[11].src = "header/re30.gif";
imgarray[12] = new Image();
imgarray[12].src = "header/re31.gif";
var timeoutValue = 300;
var animDelay = 0;
var numOfImages = 12;

</script>
<script language="javascript">
var imageIndex = 0;
var timeoutID = 0;
var playMode = 1;


function animImageInc()
{
if (imageIndex < numOfImages)
imageIndex++
else
imageIndex = 1;
}

function animImageDec()
{
if (imageIndex > 1)
imageIndex--;
else
imageIndex = numOfImages;
}

function setCurrImage()
{
document.MainImage.src = imgarray[imageIndex].src;
}

function updateAnim()
{
var currTimeoutValue;

currTimeoutValue = timeoutValue;

if (playMode == 1)
{
animImageInc();
if (imageIndex == numOfImages)
currTimeoutValue += animDelay;
}
else
{
animImageDec();
if (imageIndex == 1)
currTimeoutValue += animDelay;
}
setCurrImage();
timeoutID = setTimeout("updateAnim()", currTimeoutValue);
}
function clearLastUpdate()
{
clearTimeout(timeoutID);
timeoutID = 0;
}

function startPlay()
{
clearLastUpdate();
playMode = 1;
updateAnim();
}
function startPlayReverse()
{
clearLastUpdate();
playMode = 2;
updateAnim();
}
updateAnim();
</script>

How do I keep the animation from looping over and over? And what else do you think I can get rid of? I just want it to play once when th epage loads. It plays when the page loads but I can't get it to stop.
Thanks in advance
 
Java is not Javascript : try forum216

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top