Skip to content

Instantly share code, notes, and snippets.

Last active Dec 18, 2020
What would you like to do?
// Elements with `data-observe` toggle `data-visible`
// between `true` and `false`
if ('IntersectionObserver' in window) {
const callback = (entries, observer) => {
entries.forEach(entry => {'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