Skip to content

Instantly share code, notes, and snippets.

@akella
Created September 2, 2017 11:32
Show Gist options
  • Save akella/1581dfec03c6b7f1e45a050f12f92bc0 to your computer and use it in GitHub Desktop.
Save akella/1581dfec03c6b7f1e45a050f12f92bc0 to your computer and use it in GitHub Desktop.
Preload array of images with callback
function loadImages(paths,whenLoaded){
var imgs=[];
paths.forEach(function(path){
var img = new Image;
img.onload = function(){
imgs.push(img);
if (imgs.length==paths.length) whenLoaded(imgs);
}
img.src = path;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment