intersection Observer Basic Example

PHOTO EMBED

Fri Dec 30 2022 04:35:36 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #intersection #observer

const sections = document.querySelector('.section--2');

const options = {
  rootMargin: '0px',
  threshold: 0.8
}

function handleSections(entries){
    entries.forEach((entry) => {
    if(entry.isIntersecting){
     entry.target.classList.add()
    }else{
      entry.target.style.backgroundColor = 'transparent'
    }
    })
}

const sectionObserver = new IntersectionObserver(handleSections, options);

sectionObserver.observe(sections)
content_copyCOPY