Skip to content

Instantly share code, notes, and snippets.

@shavit shavit/index.html
Created Jun 1, 2017

Embed
What would you like to do?
Preload images on a webpage
<html>
<img src="" hide>
</html>
document
.querySelectorAll('img[hide]')
.forEach(elm => {
let img = document.createElement('img')
img.src = elm.src
img.onload = (e) => {
elm.removeAttribute('hide')
}
})
img{
transition: opacity 1s ease-out;
}
img[hide]{
opacity: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.