util.js 480 B

1234567891011121314151617
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isInViewPort = isInViewPort;
  6. function isInViewPort(element) {
  7. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  8. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  9. const {
  10. top,
  11. right,
  12. bottom,
  13. left
  14. } = element.getBoundingClientRect();
  15. return top >= 0 && left >= 0 && right <= viewWidth && bottom <= viewHeight;
  16. }