mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 03:59:01 +08:00
33 lines
945 B
TypeScript
33 lines
945 B
TypeScript
export type BindElement = HTMLElement | Window | null | undefined;
|
|
|
|
export function getTargetRect(target: BindElement): DOMRect {
|
|
return target !== window
|
|
? (target as HTMLElement).getBoundingClientRect()
|
|
: ({ top: 0, bottom: window.innerHeight } as DOMRect);
|
|
}
|
|
|
|
export function getFixedTop(placeholderRect: DOMRect, targetRect: DOMRect, offsetTop?: number) {
|
|
if (
|
|
offsetTop !== undefined &&
|
|
Math.round(targetRect.top) > Math.round(placeholderRect.top) - offsetTop
|
|
) {
|
|
return offsetTop + targetRect.top;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function getFixedBottom(
|
|
placeholderRect: DOMRect,
|
|
targetRect: DOMRect,
|
|
offsetBottom?: number,
|
|
) {
|
|
if (
|
|
offsetBottom !== undefined &&
|
|
Math.round(targetRect.bottom) < Math.round(placeholderRect.bottom) + offsetBottom
|
|
) {
|
|
const targetBottomOffset = window.innerHeight - targetRect.bottom;
|
|
return offsetBottom + targetBottomOffset;
|
|
}
|
|
return undefined;
|
|
}
|