Skip to content

Instantly share code, notes, and snippets.

@interactiveRob
Created January 18, 2023 21:18
Show Gist options
  • Save interactiveRob/44928de0d6e97090f4ca4d21af238806 to your computer and use it in GitHub Desktop.
Save interactiveRob/44928de0d6e97090f4ca4d21af238806 to your computer and use it in GitHub Desktop.
Simple on/off toggle Intersection Observer ES6 method
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