Created
January 24, 2020 04:24
-
-
Save mgmilcher/c5152dff2fc0f9df9eb8c599c5f60b20 to your computer and use it in GitHub Desktop.
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
function initLazyImages() { | |
const lazyImages = document.querySelectorAll(".lazy-image"); | |
function onIntersection(imageEntities) { | |
imageEntities.forEach(image => { | |
if (image.isIntersecting) { | |
observer.unobserve(image.target); | |
image.target.src = image.target.dataset.src; | |
} | |
}); | |
} | |
const observer = new IntersectionObserver(onIntersection); | |
lazyImages.forEach(image => observer.observe(image)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment