Simple case: I want to load several images which have a common name and a suffix, e.g: image0.png, image1.png, image2.png ... imageN.png
I'm using a simple for loop:
var images = [];
for (var i=1; i<N; i++) {
images[i] = new Image();
images[i].onload = function () {
console.log("Image " + i + " loaded");
};
images[i].src = "image" + i + ".png";
}
What I'm getting in the Console is:
Image N loaded
Image N loaded
Image N loaded
...
Image N loaded
But what I want should be like this:
Image 0 loaded
Image 1 loaded
Image 2 loaded
...
Image N loaded
Why is this happening?
How can I get my desired behavior?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…