I use a function like this to load images from an array:
for (var i = 0; i < images_list.length; i++) {
var img = new Image();
img.onload = function() {
images_objects.push(this);
showImages(images_objects);
};
img.onerror = function() {
};
img.src = images_links[i].image_url;
}
What I need to make work properly is showImages function. Its purpose is to show all loaded images with jQuery when the images_object is filled with images from the array. Now it’s placed incorrectly, just to give you an idea how I try to do it. I suppose there is something like a callback should be run after the images are loaded. How to do this better?
Just use a helper function to store the newly loaded image and to check to see if all images have been loaded, might work.