Skip to content

Instantly share code, notes, and snippets.

@niorad
Created January 30, 2016 17:16
Show Gist options
  • Save niorad/49e7b920034f5fc58779 to your computer and use it in GitHub Desktop.
Save niorad/49e7b920034f5fc58779 to your computer and use it in GitHub Desktop.
Short Vanilla-JS Image LazyLoading
<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