- Below is the JavaScript code for the image gallery
<html>
<head>
<title>Image Slideshow</title>
<script language=JAVASCRIPT type="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers
myPix = new Array("image/gallery.gif","image/scythian.jpg","image/spinboutique.jpg",
"image/curriculum.jpg","image/nature_tram.jpg","image/dragonmaker.jpg",
"image/admissions.jpg","image/communications.jpg","image/contact_dragmkr.jpg")
thisPic = 0
imgCt = myPix.length - 1
function chgSlide(direction) {
if (document.images) {
thisPic = thisPic + direction
if (thisPic > imgCt) {
thisPic = 0
}
if (thisPic < 0) {
thisPic = imgCt
}
document.myPicture.src=myPix[thisPic]
}
}
// End hiding script from old browsers -->
</script>
</head>
<body bgcolor=black>
<table align="center">
<tr>
<td>
<p ><img src="image/gallery.gif" name="myPicture"
width=400 height=221></p>
<p align="center"><a href="javascript:chgSlide(-1)"><<
Previous</a> <a href="javascript:chgSlide(1)">Next
>></a></p>
</td>
</tr>
</table>
</body>
</html>
- The JavaScript appears in two places , the <head> portion
and the <body> portion of the page.
- The <head> portion of the script
sets up an array (list) of the images.
What is great about this script is that you can keep adding images
to the array without having to redo the script. The position of the
images in the array determines when the image loads. The second image
in the array is "image/scythian.jpg". It is the second image
that loads after the user clicks the "Next" button.
- The <head> portion of the script also sets up the function
chgSlid(direction).
- The <body> portion of the script
also calls the function chgSlid(direction) when the user clicks either
the Next or Previous
buttons.
- click on the Link to copy the code.