i=i++
This is not the correct use to increment i
.
What this does:
- Variable
i
gets incremented by ++
.
- Variable
i
gets assigned old value of i
, as i++
returns the old value of i
.
So basically, you are stuck in an endless loop. Just replace i=i++
with just i++
or i=i+1
or i+=1
and you should be fine.
Looking at your code again, I have to tell you, that this will still not yield the desired effect, as you are setting all the intervals to fire at the same exact time. What you would want to do looks something like this:
function next() {
setInterval(function(){
//display next image
},3000);
next();
}
next();
Depending on how your html-code is build, the simplest way to implement this would be:
var count = 3; current = 0, img=document.getElementById("img1");
function next() {
setInterval(function(){
current++;
if(current >= count) {
current = 0;
}
img.src="Images/" + current + ".jpg";
},3000);
next();
}
next();