IT Tutorial

JAVA - Animate

This will rotate an array of images with custom timing for each image.

HTML :
<BODY onload="setTimeout('animate()',timings[timings.length - 1])">
<Img name=anim id=anim src="images/source1.gif">
</BODY>


CODE:

//Make sure the first image is always la
// st.
var srcs = new Array("source2.jpg","images/source3.gif","images/source1.gif");
//Each timing is for after the correspon
// ding image displays
var timings = new Array(100,200,300);
//specify whether or not the animation s
// hould loop
var loop = true;
var i = 0;


function animate() {
document.images["anim"].src = srcs[i]
i++


if(i < srcs.length) {
setTimeout('animate()',timings[i - 1]);
}


else {


if(loop == true) {
i = 0;
setTimeout('animate()',timings[i - 1]);
}
}
}

Reference : Matt DeKok

Planet-source-code.com


Thanx, regards !!!
Hemlet
sourcescode



JAVA - Animate