Check if element is in viewport
Fri Apr 23 2021 18:49:47 GMT+0000 (Coordinated Universal Time)
Saved by
@shm1ckle
#javascript
function isInViewport(elem) {
const bounding = elem.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
content_copyCOPY
Comments