문제

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