Preview:
document.addEventListener("DOMContentLoaded", function() {

  var lazyloadImages = document.querySelectorAll("img.lazy");    

  var lazyloadThrottleTimeout;

  

  function lazyload () {

    if(lazyloadThrottleTimeout) {

      clearTimeout(lazyloadThrottleTimeout);

    }    

    

    lazyloadThrottleTimeout = setTimeout(function() {

        var scrollTop = window.pageYOffset;

        lazyloadImages.forEach(function(img) {

            if(img.offsetTop < (window.innerHeight + scrollTop)) {

              img.src = img.dataset.src;

              img.classList.remove('lazy');

            }

        });

        if(lazyloadImages.length == 0) { 

          document.removeEventListener("scroll", lazyload);

          window.removeEventListener("resize", lazyload);

          window.removeEventListener("orientationChange", lazyload);

        }
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter