Sequential Image Changer
This script generates a slideshow using a list of images you provide. The way it does this is by creating an array of the image names, then replacing the existing image with the next one in the array. As written, the script performs this every 5 seconds, but you can set it for any length of time (more on how to do this later). To use this script, you need to insert the following into the header portion of your html document (preferably right before the
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var secs = 5;
img1 = new Image();
img1.src = "1.jpg";
img2 = new Image();
img2.src = "2.jpg";
img3 = new Image();
img3.src = "3.jpg";
img4 = new Image();
img4.src = "4.jpg";
img5 = new Image();
img5.src = "5.jpg";
img6 = new Image();
img6.src = "6.jpg";
var pics = new Array(6);
pics[0] = img1.src;
pics[1] = img2.src;
pics[2] = img3.src;
pics[3] = img4.src;
pics[4] = img5.src;
pics[5] = img6.src;
var thisPic = 0;
var placeCt = 7;
function nextPic(){
if (document.images){
thisPic++
if (thisPic == placeCt){thisPic = 0}
document.ranpic.src = pics[thisPic];
setTimeout("nextPic()",secs * 1000)
}
}
//-->
</SCRIPT>
Step 2 is to modify the Step 3 is to add the
You won't need to make any changes to the body of the document after this. You will,however, need to change the parts of the script marked in red to customize your page. The first thing to do is set the number of seconds between picture changes. This is set in the variable declaration The next variables to set are the names of the images you want to use. In the example, the names are img7 = new Image(); img7.src="7.jpg"; AND adding a new instance to the pics[6] = img7.src; Next, you will need to modify the var pics = new Array(7); Last but not least, you will need to update the var placeCt = 8; That's all there is to it! Some cautions, however:
Copyright © 2002 randomscripts, All Rights Reserved. Disclaimer |