Skip to content

Instantly share code, notes, and snippets.

@basilalex
Last active October 26, 2017 02:37
Show Gist options
  • Save basilalex/f81eb662082a3679906af17de7cca8fc to your computer and use it in GitHub Desktop.
Save basilalex/f81eb662082a3679906af17de7cca8fc to your computer and use it in GitHub Desktop.
Preload array of images with Promise
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