scinote-web/app/javascript/vue/shared/isInViewPort.js

17 lines
358 B
JavaScript
Raw Normal View History

export default function isInViewPort(el) {
2023-10-05 21:44:41 +08:00
if (!el) return;
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
(window.innerHeight ||
document.documentElement.clientHeight) &&
rect.right <=
(window.innerWidth ||
document.documentElement.clientWidth)
);
}