View Full Version : javaScript simple next button gallery

01-23-2010, 04:31 PM
Hi there, does anyone know the best way to code a gallery where its just one image showing (of 6) and when you click the next/back button it keeps moving through the pictures?

Have been playing with the code below but its from an old old tutorial so I dont know if its compliant, cant get it working anyway. My images are names image1.jpg through to image6.jpeg

Can anyone see whats wrong with it, or surgest another option?

= filename;
function changeImage(direction) {
which_image_loaded += direction;
if (which_image_loaded < 0)
which_image_loaded = NUMBER_OF_IMAGES - 1;
if (which_image_loaded == NUMBER_OF_IMAGES)
which_image_loaded = 0;
if (document.images)
document.myimage.src = ImageNames[which_image_loaded];
<div><a href="javascript:changeImage(-1)"><img src="images/temp/arrowback.gif" width="28" height="18" /></a>
<a href="javascript:changeImage(1)"><img src="images/temp/arrownext.gif" width="28" height="18" /></a>
<div><img src="images/temp/image1.jpg" width="300" height="400" /></div>

01-23-2010, 05:56 PM
IF it's too old, check out jQuery and the Cycle plugin.