javascript - Image Slideshow in js hanging app -


i have written method in javascript:

function displayimage() {     window.setinterval(function(){        (var = 1; <= 4; i++) {            document.getelementbyid("img1").setattribute("src",                    "images/th-" + + ".jpg");            if(i==4){                i=0;            }        }    }, 3000);      } 

and calling method html page: . after 3 sec, application hangs , nothing happens. going wrong in this?

in case for loop work 4 times after every 3000 milliseconds. need change 1 picture after each 3000 milliseconds.

try this

function displayimage() {     var img = document.getelementbyid("img1");    var imgindex = 1;     window.setinterval(function(){        img.setattribute("src", "images/th-" + imgindex + ".jpg");        imgindex = imgindex === 3 ? 0 : imgindex + 1;    }, 3000); } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -