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="javascriptrevpicture(0, imagearray1, currentelement1,
lastelement1)">Previous</a><br>
<a href="javascript:nextpicture(0, imagearray1, currentelement1,
lastelement1)">Next</a><br>
</body>
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="javascriptrevpicture(0, imagearray1, currentelement1,
lastelement1)">Previous</a><br>
<a href="javascript:nextpicture(0, imagearray1, currentelement1,
lastelement1)">Next</a><br>
</body>