perf(anchor): reduce unnecessary calculations (#6516)

pull/6524/head
Simon He 2023-05-03 13:14:59 +08:00 committed by GitHub
parent 019b539f16
commit b39f2b2d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -131,8 +131,6 @@ export default defineComponent({
const { offsetTop, targetOffset } = props; const { offsetTop, targetOffset } = props;
setCurrentActiveLink(link); setCurrentActiveLink(link);
const container = getContainer.value();
const scrollTop = getScroll(container, true);
const sharpLinkMatch = sharpMatcherRegx.exec(link); const sharpLinkMatch = sharpMatcherRegx.exec(link);
if (!sharpLinkMatch) { if (!sharpLinkMatch) {
return; return;
@ -142,6 +140,8 @@ export default defineComponent({
return; return;
} }
const container = getContainer.value();
const scrollTop = getScroll(container, true);
const eleOffsetTop = getOffsetTop(targetElement, container); const eleOffsetTop = getOffsetTop(targetElement, container);
let y = scrollTop + eleOffsetTop; let y = scrollTop + eleOffsetTop;
y -= targetOffset !== undefined ? targetOffset : offsetTop || 0; y -= targetOffset !== undefined ? targetOffset : offsetTop || 0;