is-in-browser-viewport
Version:
A package that checks if an element is in the browser viewport and provides a callback function when the element is in the viewport and when the element leaves the viewport
16 lines (11 loc) • 412 B
JavaScript
export class isInViewport {
constructor(targetElement, callback, options) {
this.isInViewport(targetElement, callback, options)
}
isInViewport(targetElement, callback, options) {
// console.log(targetElement, callback, options);
let observer;
observer = new IntersectionObserver(callback, options);
observer.observe(targetElement);
}
}