diff --git a/src/client/theme-default/composables/activeSidebarLink.ts b/src/client/theme-default/composables/activeSidebarLink.ts index 9a7d8a49..de98c7a0 100644 --- a/src/client/theme-default/composables/activeSidebarLink.ts +++ b/src/client/theme-default/composables/activeSidebarLink.ts @@ -96,14 +96,16 @@ function isAnchorActive( nextAnchor: HTMLAnchorElement ): [boolean, string | null] { const scrollTop = window.scrollY - const anchorTop = getAnchorTop(anchor) - const nextAnchorTop = getAnchorTop(nextAnchor) if (index === 0 && scrollTop === 0) { return [true, null] } - if (scrollTop >= anchorTop && (!nextAnchor || scrollTop < nextAnchorTop)) { + if (scrollTop < getAnchorTop(anchor)) { + return [false, null] + } + + if (!nextAnchor || scrollTop < getAnchorTop(nextAnchor)) { return [true, decodeURIComponent(anchor.hash)] }