Hi everyone,
I’m having a little trouble with a JavaScript script. It’s a picture slide show.
Basically, when I click ‘Previous’ to call the ‘moveToPreviousSlide’ function, on the first call, it increments instead of decrements.
Say I’m currently viewing image 3, when I then click ‘previous’, it keeps going to image 4 instead, and then goes back down to 3, and then 2, instead of going straight to 2.
Here is what I’ve made so far:
[CODE]<script type=”text/javascript”>
var index = 0;
var titles = [1,2,3,4,5,6];
function moveToNextSlide()
{
if(index > 5)
{
index = 0;
}
var slideName = “images/slideshow/template” + titles[index++] + “.jpg”;
var img1 = document.getElementById(“img1”);
img1.src = slideName;
}
function moveToPreviousSlide()//on first call still increments by 1
{
var slideName = “images/slideshow/template” + titles[index–] + “.jpg”;
var img1 = document.getElementById(“img1”);
img1.src = slideName;
}
moveToNextSlide();
</script>
I’ve tried switching from post and pre increment / decrement, and a combination of the two, but this isn’t correcting it.
If anyone can spot where the problem is, it would be very much appreciated.
many thanks!
?