Last active
September 3, 2019 02:54
-
-
Save mandymichael/69f79de5d0083aebfb290c6ce401dc70 to your computer and use it in GitHub Desktop.
This file contains 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
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