Animated Image
This script is useful if you need to animate an image other then a *.gif. The script
is started by onload="timeimgs('2');" in the body tag. It does require some
customization so only experienced developers should use it. If you wanted the images
to change every 5 seconds change the '1000' in
thetimer = setTimeout("imgturn('" +numb+ "')", 1000); to 5000.
<html>
<head>
<title></title>
<script language="JavaScript">
<!--
if (document.images) { // Preloaded images
demo1 = new Image();
demo1.src = "../../images/demo1.jpg";
demo2 = new Image();
demo2.src = "../../images/demo2.jpg";
demo3 = new Image();
demo3.src = "../../images/demo3.jpg";
}
function timeimgs(numb) { // Reusable timer
thetimer = setTimeout("imgturn('" +numb+ "')", 1000);
}
function imgturn(numb) { // Reusable image turner
if (document.images) {
if (numb == "3") { // This will loop the image
document["demo"].src = eval("demo3.src");
timeimgs('1');
}
else {
document["demo"].src = eval("demo" + numb + ".src");
timeimgs(numb = ++numb);
}
}
}
// -->
</script>
</head>
<body onload="timeimgs('2');">
<img src="../../images/demo1.jpg" name="demo" width="100" height="100" alt="demo">
Notes:
- Please follow the instructions above.
- To ensure the code is copied correctly, please click here.
