Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created December 21, 2009 15:02
Show Gist options
  • Save jakearchibald/260977 to your computer and use it in GitHub Desktop.
Save jakearchibald/260977 to your computer and use it in GitHub Desktop.
function preloadImages(imageUrls, callback) {
var images = [],
imagesLen = imageUrls.length,
loaded = 0,
image;
function imageLoaded() {
if (++loaded == imagesLen) {
callback(images);
}
}
for (var i = 0; i < imagesLen; i++) {
image = new Image();
image.onload = imageLoaded;
image.src = imageUrls[i];
images.push(image);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment