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="javas cript">
<!--
var imagearray1 = new Array("./image1.gif","./image2.gif");
var lastelement1 = imagearray1.len gth - 1;
var currentelement1 = 0;
function showpicture(ima geindex, imagearray, current)
{
document.images[imageindex].src=imagearray[current];
}
function nextpicture(ima geindex, imagearray, current, last)
{
current += 1;
if (current>last)
{
current = 0;
}
showpicture(ima geindex, imagearray, current);
}
function prevpicture(ima geindex, imagearray, current, last)
{
current -= 1;
if (current < 0)
{
current = last;
}
showpicture(ima geindex, imagearray, current);
}
-->
</script>
<body>
<img src="image1.gif "><br>
<a href="javascrip t:prevpicture(0 , imagearray1, currentelement1 ,
lastelement1)"> Previous</a><br>
<a href="javascrip t: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="javas cript">
<!--
var imagearray1 = new Array("./image1.gif","./image2.gif");
var lastelement1 = imagearray1.len gth - 1;
var currentelement1 = 0;
function showpicture(ima geindex, imagearray, current)
{
document.images[imageindex].src=imagearray[current];
}
function nextpicture(ima geindex, imagearray, current, last)
{
current += 1;
if (current>last)
{
current = 0;
}
showpicture(ima geindex, imagearray, current);
}
function prevpicture(ima geindex, imagearray, current, last)
{
current -= 1;
if (current < 0)
{
current = last;
}
showpicture(ima geindex, imagearray, current);
}
-->
</script>
<body>
<img src="image1.gif "><br>
<a href="javascrip t:prevpicture(0 , imagearray1, currentelement1 ,
lastelement1)"> Previous</a><br>
<a href="javascrip t:nextpicture(0 , imagearray1, currentelement1 ,
lastelement1)"> Next</a><br>
</body>
Comment