I want to use setTimeout to delay the increment counter in the loop in order to change picture every secs. I try to delay the updatePic() use setTimeout but it doesn't work either. Please help. Thanks.
My JS code:
function picAnimation() {
//var pic = document.getElementById('pic').src;
for(i = 2; i < 25; ) {
updatePic(i);
setTimeout(function() {increment(i);} , 1000);
}
}
function updatePic(i) {
if(i > 9) {
document.getElementById('pic').src = "./animation/0" + i + ".png";
} else {
document.getElementById('pic').src = "./animation/00" + i + ".png";
}
}
function increment(i) {
i++;
}
picAnimation();
My html code:
<center><img id = "pic" src="./animation/001.png" alt="N/A" width="800" height="300"></center>