Image Scrolling Problem

J

Jason Ferguson

I have created some simple code to allow me to flip through thumbnail
images via "Previous" and "Next" links. The idea is that I can have
multiple sets of images that can be scrolled through, via
document.images[<n>].src.

However, the problem is, once the "last" image is reached, the code
refuses to go back to the "first" image.

Help is appreciated.

<title>Test Page</title>
</head>

<script language="javascript">
<!--
var imagearray1 = new Array("./image1.gif","./image2.gif");
var lastelement1 = imagearray1.length - 1;
var currentelement1 = 0;


function showpicture(imageindex, imagearray, current)
{
document.images[imageindex].src=imagearray[current];
}

function nextpicture(imageindex, imagearray, current, last)
{
current += 1;

if (current>last)
{
current = 0;
}

showpicture(imageindex, imagearray, current);


}

function prevpicture(imageindex, imagearray, current, last)
{

current -= 1;

if (current < 0)
{
current = last;
}

showpicture(imageindex, imagearray, current);

}


-->
</script>

<body>
<img src="image1.gif"><br>
<a href="javascript:prevpicture(0, imagearray1, currentelement1,
lastelement1)">Previous</a><br>
<a href="javascript:nextpicture(0, imagearray1, currentelement1,
lastelement1)">Next</a><br>

</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top