Skip to content

Instantly share code, notes, and snippets.

@Ahrengot
Created October 13, 2015 11:04
Show Gist options
  • Save Ahrengot/726d224a18493a493188 to your computer and use it in GitHub Desktop.
Save Ahrengot/726d224a18493a493188 to your computer and use it in GitHub Desktop.
import $ from 'jquery'
export default class ImageLoader {
constructor(images) {
if ( typeof images === 'string' ) {
images = [images];
}
let promises = images.map(this.loadImage);
return $.when.apply($, promises);
}
loadImage(src) {
let dfd = new $.Deferred();
let img = new Image();
img.src = src;
img.addEventListener("load", dfd.resolve);
return dfd.promise();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment