-
-
Save waspar/f31b9e9d6ea0d77dd5814cc1a0b42c89 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