Created
January 30, 2019 14:50
-
-
Save pavlo-bondarchuk/93dae58332e170ce612cf3519d1006a0 to your computer and use it in GitHub Desktop.
lazy-load image
This file contains hidden or 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
<img src="data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" data-src="your-image-here"> | |
<script> | |
function init() { | |
var imgDefer = document.getElementsByTagName('img'); | |
for (var i=0; i<imgDefer.length; i++) { | |
if(imgDefer[i].getAttribute('data-src')) { | |
imgDefer[i].setAttribute('src',imgDefer[i].getAttribute('data-src')); | |
} } } | |
window.onload = init; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment