Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Preload multiple images
function loadImgs(urls, doneCallback) {
var remaining = total = urls.length;
var imgs = [];
function imgLoad(url) {
if (!--remaining) {
doneCallback(imgs);
}
}
for (var i = urls.length - 1; i >= 0; i--) {
var url = urls[i];
(function(url) {
var img = new Image();
imgs.push(img);
img.onload = function() {
imgLoad.call(this, url);
};
img.src = url;
})(url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.