UNPKG

737 BJavaScriptView Raw
1export function getTargetRect(target) {
2 return target !== window ? target.getBoundingClientRect() : {
3 top: 0,
4 bottom: window.innerHeight
5 };
6}
7export 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}
13export 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}
\No newline at end of file