Last active
September 21, 2017 19:14
-
-
Save aganglada/6bec549c66c794232cea6e966dcd575c to your computer and use it in GitHub Desktop.
Intersection Observer
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
if (!this.props.observeOnScroll) { | |
return false | |
} | |
this.observer = new IntersectionObserver(entries => { | |
entries.forEach(entry => { | |
const { isIntersecting, intersectionRatio } = entry | |
if (isIntersecting === true || intersectionRatio > 0) { | |
this.createImage() | |
this.setState({ intersecting: true }) | |
this.observer.disconnect() | |
this.observer = null | |
} | |
}) | |
}, {}) | |
this.observer.observe(this.element) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment