Last active
July 18, 2018 13:17
-
-
Save darolo/287471af4f7eb3063e9c22a564766101 to your computer and use it in GitHub Desktop.
Verify when a collection of image url loads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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