Skip to content

Instantly share code, notes, and snippets.

@aganglada
Last active September 21, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aganglada/6bec549c66c794232cea6e966dcd575c to your computer and use it in GitHub Desktop.
Save aganglada/6bec549c66c794232cea6e966dcd575c to your computer and use it in GitHub Desktop.
Intersection Observer
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