Last active
October 26, 2017 02:37
-
-
Save basilalex/f81eb662082a3679906af17de7cca8fc to your computer and use it in GitHub Desktop.
Preload array of images with Promise
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
export default arr => new Promise((resolve) => { | |
const imgs = []; | |
arr.forEach((path) => { | |
const img = new Image(); | |
img.onload = () => { | |
imgs.push(img); | |
if (imgs.length === arr.length) resolve(imgs); | |
}; | |
img.src = `../img/phone/phone_000${path}`; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment