Created
August 7, 2017 15:54
-
-
Save deanhume/768666a8b37dce069d5ce7839100a4e4 to your computer and use it in GitHub Desktop.
Intersection Observer - Lazy Load - On Intersection
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 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