Skip to content

Instantly share code, notes, and snippets.

@josephscott
Last active August 2, 2019 20:44
Show Gist options
  • Save josephscott/ab9d7bc61b1f2134684400b4470e63c3 to your computer and use it in GitHub Desktop.
Save josephscott/ab9d7bc61b1f2134684400b4470e63c3 to your computer and use it in GitHub Desktop.
document.addEventListener("DOMContentLoaded",function(){var e=[].slice.call(document.getElementsByClassName("js-lazy-img"));if("IntersectionObserver"in window){var t=new IntersectionObserver(function(e,s){e.forEach(function(e){if(e.isIntersecting){var s=e.target;s.src=s.dataset.src,s.dataset.srcset&&(s.srcset=s.dataset.srcset),t.unobserve(s)}})},{rootMargin:"250px 0px"});e.forEach(function(e){t.observe(e)})}else e.forEach(function(e){e.src=e.dataset.src,e.dataset.srcset&&(e.srcset=e.dataset.srcset)})});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment