created this simple image array gallery

javascript function call not looping the image array

var imagecount=0;
var imageArray = ["images/1.jpg","images/2.jpg","images/3.jpg","images/4.jpg"];
var allimages=imageArray.length-1;


function next()
{
    imagecount++;
    if(imagecount>allimages) {
      imagecount=0;
    }
    document.getElementById("slideshow").src=imageArray[imagecount];
}

function prev()
{
    imagecount--;
    if(imagecount<0) {
      imagecount=allimages;
    }
    document.getElementById("slideshow").src=imageArray[imagecount];
}

document.getElementById("next").onclick=next;

document.getElementById("previous").onclick=prev;

as i am calling the function in javascript itself the image gallery is not looping

有帮助吗?

解决方案

Check this fiddle out, it is exactly your code and it just works to me..

This is probably a browser specific problem..

其他提示

You are mostly likely exceeding the array bounds. Change:

if(imagecount>allimages){

to

if(imagecount>allimages-1){
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top