Created
July 24, 2017 01:07
-
-
Save jordanbrauer/35748d5ba4bab51bfc64009e8c39461a to your computer and use it in GitHub Desktop.
Preload images on page
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
preloadImages() { | |
let i = 0; | |
const arr = [...Backgrounds, ...Images]; | |
return new Promise(resolve => { | |
arr.map(filename => { | |
const img = new Image(); | |
img.src = filename; | |
img.onload = () => (++i == arr.length) ? resolve() : 1; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment