perf(affix): reduce unnecessary calculations (#6509)
parent
ccf850552d
commit
019b539f16
|
@ -109,31 +109,48 @@ const Affix = defineComponent({
|
||||||
const newState = {
|
const newState = {
|
||||||
status: AffixStatus.None,
|
status: AffixStatus.None,
|
||||||
} as AffixState;
|
} as AffixState;
|
||||||
const targetRect = getTargetRect(targetNode);
|
|
||||||
const placeholderRect = getTargetRect(placeholderNode.value as HTMLElement);
|
const placeholderRect = getTargetRect(placeholderNode.value as HTMLElement);
|
||||||
|
|
||||||
|
if (
|
||||||
|
placeholderRect.top === 0 &&
|
||||||
|
placeholderRect.left === 0 &&
|
||||||
|
placeholderRect.width === 0 &&
|
||||||
|
placeholderRect.height === 0
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetRect = getTargetRect(targetNode);
|
||||||
const fixedTop = getFixedTop(placeholderRect, targetRect, offsetTop.value);
|
const fixedTop = getFixedTop(placeholderRect, targetRect, offsetTop.value);
|
||||||
const fixedBottom = getFixedBottom(placeholderRect, targetRect, offsetBottom.value);
|
const fixedBottom = getFixedBottom(placeholderRect, targetRect, offsetBottom.value);
|
||||||
|
|
||||||
if (fixedTop !== undefined) {
|
if (fixedTop !== undefined) {
|
||||||
|
const width = `${placeholderRect.width}px`;
|
||||||
|
const height = `${placeholderRect.height}px`;
|
||||||
|
|
||||||
newState.affixStyle = {
|
newState.affixStyle = {
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
top: fixedTop,
|
top: fixedTop,
|
||||||
width: placeholderRect.width + 'px',
|
width,
|
||||||
height: placeholderRect.height + 'px',
|
height,
|
||||||
};
|
};
|
||||||
newState.placeholderStyle = {
|
newState.placeholderStyle = {
|
||||||
width: placeholderRect.width + 'px',
|
width,
|
||||||
height: placeholderRect.height + 'px',
|
height,
|
||||||
};
|
};
|
||||||
} else if (fixedBottom !== undefined) {
|
} else if (fixedBottom !== undefined) {
|
||||||
|
const width = `${placeholderRect.width}px`;
|
||||||
|
const height = `${placeholderRect.height}px`;
|
||||||
|
|
||||||
newState.affixStyle = {
|
newState.affixStyle = {
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
bottom: fixedBottom,
|
bottom: fixedBottom,
|
||||||
width: placeholderRect.width + 'px',
|
width,
|
||||||
height: placeholderRect.height + 'px',
|
height,
|
||||||
};
|
};
|
||||||
newState.placeholderStyle = {
|
newState.placeholderStyle = {
|
||||||
width: placeholderRect.width + 'px',
|
width,
|
||||||
height: placeholderRect.height + 'px',
|
height,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue