refactor(components): [affix] optimized code logic (#17929)

* perf(components): [affix] optimized code logic

* perf(components): [affix] restore the original writing
This commit is contained in:
Kylin
2024-08-20 11:42:06 +08:00
committed by GitHub
parent 4984d1b014
commit 97652eb14b

View File

@@ -74,27 +74,26 @@ const update = () => {
? document.documentElement.scrollTop
: scrollContainer.value.scrollTop || 0
if (props.position === 'top') {
if (props.target) {
const difference =
targetRect.bottom.value - props.offset - rootHeight.value
fixed.value = props.offset > rootTop.value && targetRect.bottom.value > 0
const { position, target, offset } = props
const rootHeightOffset = offset + rootHeight.value
if (position === 'top') {
if (target) {
const difference = targetRect.bottom.value - rootHeightOffset
fixed.value = offset > rootTop.value && targetRect.bottom.value > 0
transform.value = difference < 0 ? difference : 0
} else {
fixed.value = props.offset > rootTop.value
fixed.value = offset > rootTop.value
}
} else if (props.target) {
} else if (target) {
const difference =
windowHeight.value -
targetRect.top.value -
props.offset -
rootHeight.value
windowHeight.value - targetRect.top.value - rootHeightOffset
fixed.value =
windowHeight.value - props.offset < rootBottom.value &&
windowHeight.value - offset < rootBottom.value &&
windowHeight.value > targetRect.top.value
transform.value = difference < 0 ? -difference : 0
} else {
fixed.value = windowHeight.value - props.offset < rootBottom.value
fixed.value = windowHeight.value - offset < rootBottom.value
}
}