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)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter