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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -