Created
May 4, 2018 11:56
-
-
Save gsimone/2c93686c8505b277898c184be47c300c to your computer and use it in GitHub Desktop.
Wait for all images
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
const images = ['http://picsum.photos/300/300?r&a=1', 'http://picsum.photos/300/300?r&a=2', 'http://picsum.photos/300/300?r&a=3'] | |
const imageLoadPromise = (src) => new Promise((resolve, reject) => { | |
const img = new Image() | |
img.onload = resolve | |
img.src = src | |
}) | |
Promise.all(images.map(imageLoadPromise)) | |
.then(() => console.log('all done')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment