Skip to content

Instantly share code, notes, and snippets.

@leeoniya
Created July 17, 2013 16:18
Show Gist options
  • Save leeoniya/6022090 to your computer and use it in GitHub Desktop.
Save leeoniya/6022090 to your computer and use it in GitHub Desktop.
jquery, promise-based multi-image loader
$.getImgs = function(srcs, fn) {
var jqry = this,
dfds = [],
prms = [];
jqry.each(srcs, function(i, src) {
var img = new Image(),
dfd = jqry.Deferred();
dfds.push(dfd);
prms.push(dfd.promise());
img.onload = function() {
dfd.resolve(this);
};
img.src = src;
});
jqry.when.apply(jqry, prms).done(fn);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment