Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created August 7, 2017 15:54
Show Gist options
  • Save deanhume/768666a8b37dce069d5ce7839100a4e4 to your computer and use it in GitHub Desktop.
Save deanhume/768666a8b37dce069d5ce7839100a4e4 to your computer and use it in GitHub Desktop.
Intersection Observer - Lazy Load - On Intersection
function onIntersection(entries) {
// Loop through the entries
entries.forEach(entry => {
// Are we in viewport?
if (entry.intersectionRatio > 0) {
// Stop watching and load the image
observer.unobserve(entry.target);
preloadImage(entry.target);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment