Created
September 2, 2017 11:32
-
-
Save akella/1581dfec03c6b7f1e45a050f12f92bc0 to your computer and use it in GitHub Desktop.
Preload array of images with callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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