utils.js 737 B

12345678910111213141516171819
  1. export function getTargetRect(target) {
  2. return target !== window ? target.getBoundingClientRect() : {
  3. top: 0,
  4. bottom: window.innerHeight
  5. };
  6. }
  7. export function getFixedTop(placeholderRect, targetRect, offsetTop) {
  8. if (offsetTop !== undefined && Math.round(targetRect.top) > Math.round(placeholderRect.top) - offsetTop) {
  9. return offsetTop + targetRect.top;
  10. }
  11. return undefined;
  12. }
  13. export function getFixedBottom(placeholderRect, targetRect, offsetBottom) {
  14. if (offsetBottom !== undefined && Math.round(targetRect.bottom) < Math.round(placeholderRect.bottom) + offsetBottom) {
  15. const targetBottomOffset = window.innerHeight - targetRect.bottom;
  16. return offsetBottom + targetBottomOffset;
  17. }
  18. return undefined;
  19. }