/** * Checks if the DOM element is visible in the current viewport. * @param element * @param offset * @returns */ const isVisibleInViewport = ( element: HTMLElement, offset?: Pick ) => { const rect = element.getBoundingClientRect(); return ( rect.top + (offset?.top || 0) >= 0 && rect.left + (offset?.left || 0) >= 0 && rect.bottom - (offset?.bottom || 0) <= (window.innerHeight || document.documentElement.clientHeight) && rect.right - (offset?.right || 0) <= (window.innerWidth || document.documentElement.clientWidth) ); }; export default isVisibleInViewport;