Skip to content

Instantly share code, notes, and snippets.

@mandymichael
Last active September 3, 2019 02:54
Show Gist options
  • Save mandymichael/69f79de5d0083aebfb290c6ce401dc70 to your computer and use it in GitHub Desktop.
Save mandymichael/69f79de5d0083aebfb290c6ce401dc70 to your computer and use it in GitHub Desktop.
componentDidMount() {
this.detectInViewport()
addListener('scroll', this.detectInViewport)
addListener('resize', this.detectInViewport)
}
detectInViewport = () => {
const { top, bottom, height } = this.innerRef.getBoundingClientRect()
// Calculate if on screen and distance from the viewport...
this.setState({ inViewport: viewportPosition, viewportHeight, distanceFromViewport })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment