util.js 370 B

1234567891011
  1. export function isInViewPort(element) {
  2. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  3. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  4. const {
  5. top,
  6. right,
  7. bottom,
  8. left
  9. } = element.getBoundingClientRect();
  10. return top >= 0 && left >= 0 && right <= viewWidth && bottom <= viewHeight;
  11. }