Skip to content

Instantly share code, notes, and snippets.

@darolo
Last active July 18, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darolo/287471af4f7eb3063e9c22a564766101 to your computer and use it in GitHub Desktop.
Save darolo/287471af4f7eb3063e9c22a564766101 to your computer and use it in GitHub Desktop.
Verify when a collection of image url loads
(function(w, d, $, undefined){
$.LoadImages = function(){
var deferreds = [];
$.each(arguments, function(i, url){
var
img = d.createElement('img'),
def = deferreds[i] = $.Deferred();
img.src = url.toString();
img.onload = function(){ def.resolve(url) };
img.onerror = function(){ def.reject(url) };
});
return $.when.apply($, deferreds);
}
}(window, document, jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment