I have an array of image IDs.
var images = ['238239', '389943', '989238', ... ];
max = images.length;
Array index obviously starts at 0. The array size can vary.
For example. If there are 5 images in the array, the indexes are 0, 1, 2, 3, 4.
I'm swapping the images with Jquery by incrementing the current index like so:
<script>
currindex = 0
// Previous image, onclick event swap
$("previous").click(function(){
currindex = (currindex+1) % max;
...some more code to swap image...
});
// Next image, onclick event swap
$("next").click(function(){
currindex = (currindex+max-1) % max;
...some more code to swap image...
}
</script>
This allows the images to rotate and begin again at index 0 when user clicks "Next" on last index nr. 4. The same applies to rotating with "Previous".
I want to display a counter of current position like so:
<div>Image 3 of 5</div>
How can I implement the counter which will always begin at 1 at index 0 and will rotate both ways?