intersection observer with loop

PHOTO EMBED

Fri Jul 05 2024 00:40:42 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #scroll #intersectionobserver #observer

 const options = {
        rootMargin: '0px 0px -200px 0px'
    }

    const observer = new IntersectionObserver((entries, observer) => {
        entries.forEach(entry => {
            if(entry.isIntersecting) {
                entry.target.classList.add('show');
                observer.unobserve(entry.target);
            } else {
                return;
            }
        })
    }, options);

    const h1 = document.querySelector('h1'); // targets one element
    observer.observe(h1);

    const paras = document.querySelectorAll('p'); 
    paras.forEach(p => observer.observe(p)); //targets multple element with a loop
content_copyCOPY