Created
January 18, 2023 21:18
-
-
Save interactiveRob/44928de0d6e97090f4ca4d21af238806 to your computer and use it in GitHub Desktop.
Simple on/off toggle Intersection Observer ES6 method
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
createObserver() { | |
let intersectionObserver = new IntersectionObserver((entries) => { | |
if (entries[0].intersectionRatio <= 0) { | |
//do something when hidden | |
console.log('hidden'); | |
} else { | |
//do something when visible | |
console.log('visible'); | |
} | |
}); | |
intersectionObserver.observe(this.node); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment