utils.js 911 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getFixedBottom = getFixedBottom;
  6. exports.getFixedTop = getFixedTop;
  7. exports.getTargetRect = getTargetRect;
  8. function getTargetRect(target) {
  9. return target !== window ? target.getBoundingClientRect() : {
  10. top: 0,
  11. bottom: window.innerHeight
  12. };
  13. }
  14. function getFixedTop(placeholderRect, targetRect, offsetTop) {
  15. if (offsetTop !== undefined && Math.round(targetRect.top) > Math.round(placeholderRect.top) - offsetTop) {
  16. return offsetTop + targetRect.top;
  17. }
  18. return undefined;
  19. }
  20. function getFixedBottom(placeholderRect, targetRect, offsetBottom) {
  21. if (offsetBottom !== undefined && Math.round(targetRect.bottom) < Math.round(placeholderRect.bottom) + offsetBottom) {
  22. const targetBottomOffset = window.innerHeight - targetRect.bottom;
  23. return offsetBottom + targetBottomOffset;
  24. }
  25. return undefined;
  26. }