Created
January 21, 2019 11:04
-
-
Save martinsoender/769af387e95a66c17d23f793e7cbe450 to your computer and use it in GitHub Desktop.
Intersection observer (react example)
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
// IE 11, Safari and Safari iOS safeguard | |
if (typeof IntersectionObserver === 'undefined') { | |
setActive(true) | |
return | |
} | |
const signupButton = document.querySelector('.banner .button') | |
const observer = new IntersectionObserver(entry => { | |
entry = entry[0] | |
if (entry.intersectionRect.x > 0) { | |
setActive(false) | |
} else { | |
setActive(true) | |
} | |
}) | |
if (signupButton) { | |
observer.observe(signupButton) | |
} | |
return () => { | |
observer.disconnect() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment