Intersection Observer

PHOTO EMBED

Wed Apr 19 2023 17:10:01 GMT+0000 (Coordinated Universal Time)

Saved by @markporo #intersection #observer

 const options = {
    root: document.getElementById('some-id'), // leave blank for viewport
    rootMargin: '0px',
    threshold: 1.0,
  };
  
  const observer = new IntersectionObserver(observeTestamonialInViewPortCB, options);

  const observeTestamonialInViewPortCB = (entries, observer) => {
    entries.forEach((entry) => {
      log(entry);
	// to stop observer:
	observer.unobserve();
    });
  };

  const target = document.getElementById('target-element');
  observer.observe(target);
content_copyCOPY

boiler plate