Created
January 30, 2016 17:16
-
-
Save niorad/49e7b920034f5fc58779 to your computer and use it in GitHub Desktop.
Short Vanilla-JS Image LazyLoading
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-src="myphoto.jpg" class="js-lazyload" alt="Photo"> | |
<noscript> | |
<img src="myphoto.jpg" alt="Photo"> | |
</noscript> | |
<script> | |
var images = document.getElementsByClassName("js-lazyload"); | |
for(var i = 0; i < images.length; i++) { | |
images[i].attributes.src.value = images[i].attributes["data-src"].value; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment