Intersection Observer basic example

const el = document.querySelector('.element-to-observe'); function observeIntersection() { const options = { rootMargin: '0px', threshold: 0 }; const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { console.log('on'); } else { console.log('off'); } }); }, options); observer.observe(el); } observeIntersection();

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.