I am loading images dynamic inside loop.I have some requirement such that in following code when I am loading image then and then only alert fire and when alert 1 fires then
To convert image loading into a (jQuery) promise, use:
function imageLoad(url) {
return $.Deferred(function(def) {
var img = new Image();
img.onload = function() {
def.resolve(img);
};
img.src = url;
});
}
You can then create an array of Promises for your images:
var promises = imggg.map(imageLoad);
and then pass that to $.when
:
$.when.apply($, promises).then(function() {
console.log("all images loaded");
});