-
-
Save antenando/6fbeb818bd1d4543200df7c68b0cad2f 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
// Elements with `data-observe` toggle `data-visible` | |
// between `true` and `false` | |
if ('IntersectionObserver' in window) { | |
const callback = (entries, observer) => { | |
entries.forEach(entry => { | |
entry.target.setAttribute('data-visible', entry.isIntersecting) | |
}) | |
} | |
const observer = new IntersectionObserver(callback) | |
const targets = document.querySelectorAll('[data-observe]') | |
targets.forEach(t => observer.observe(t)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment