1function isInViewport(element) {
2 const rect = element.getBoundingClientRect();
3 return (
4 rect.top >= 0 &&
5 rect.left >= 0 &&
6 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
7 rect.right <= (window.innerWidth || document.documentElement.clientWidth)
8 );
9}