Observes an element's visibility via IntersectionObserver.
Returns a cleanup function that disconnects the observer.
Optional
const stop = watchVisibility(img, (entry) => { if (entry.isIntersecting) loadImage(img); }, { threshold: 0.5, once: true }); Copy
const stop = watchVisibility(img, (entry) => { if (entry.isIntersecting) loadImage(img); }, { threshold: 0.5, once: true });
Observes an element's visibility via IntersectionObserver.
Returns a cleanup function that disconnects the observer.