fix: fix Affix placeholder height anomaly when browser zoom is 80%

Signed-off-by: zhipenglin <sunandmoon001@163.com>
This commit is contained in:
zhipenglin 2024-01-27 21:56:31 +08:00 committed by GitHub
parent 62df041f03
commit f613db0226
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,7 @@ export function getTargetRect(target: BindElement): DOMRect {
} }
export function getFixedTop(placeholderRect: DOMRect, targetRect: DOMRect, offsetTop?: number) { export function getFixedTop(placeholderRect: DOMRect, targetRect: DOMRect, offsetTop?: number) {
if (offsetTop !== undefined && targetRect.top > placeholderRect.top - offsetTop) { if (offsetTop !== undefined && Math.round(targetRect.top) > Math.round(placeholderRect.top) - offsetTop) {
return offsetTop + targetRect.top; return offsetTop + targetRect.top;
} }
return undefined; return undefined;
@ -18,7 +18,7 @@ export function getFixedBottom(
targetRect: DOMRect, targetRect: DOMRect,
offsetBottom?: number, offsetBottom?: number,
) { ) {
if (offsetBottom !== undefined && targetRect.bottom < placeholderRect.bottom + offsetBottom) { if (offsetBottom !== undefined && Math.round(targetRect.bottom) < Math.round(placeholderRect.bottom) + offsetBottom) {
const targetBottomOffset = window.innerHeight - targetRect.bottom; const targetBottomOffset = window.innerHeight - targetRect.bottom;
return offsetBottom + targetBottomOffset; return offsetBottom + targetBottomOffset;
} }