Created
August 11, 2017 18:19
-
-
Save sergeh/4e943cda841b3b39576ed3d13c59e8b5 to your computer and use it in GitHub Desktop.
Intersection Observer - Image lazy load
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
// Get all of the images that are marked up to lazy load | |
const images = document.querySelectorAll('.js-lazy-image'); | |
const config = { | |
// If the image gets within 50px in the Y axis, start the download. | |
rootMargin: '50px 0px', | |
threshold: 0.01 | |
}; | |
// The observer for the images on the page | |
let observer = new IntersectionObserver(onIntersection, config); | |
images.forEach(image => { | |
observer.observe(image); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment