Skip to content

Instantly share code, notes, and snippets.

@jordanbrauer
Created July 24, 2017 01:07
Show Gist options
  • Save jordanbrauer/35748d5ba4bab51bfc64009e8c39461a to your computer and use it in GitHub Desktop.
Save jordanbrauer/35748d5ba4bab51bfc64009e8c39461a to your computer and use it in GitHub Desktop.
Preload images on page
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