diff --git a/src/client/theme-default/composables/outline.ts b/src/client/theme-default/composables/outline.ts index ff9eca27..c8511626 100644 --- a/src/client/theme-default/composables/outline.ts +++ b/src/client/theme-default/composables/outline.ts @@ -194,14 +194,24 @@ export function useActiveAnchor( } const activeLink = prevActiveLink - + const asideContainer = + container.value.parentElement?.parentElement?.parentElement if (activeLink) { + const offsetTop = activeLink.offsetTop + 39 + const rect = activeLink.getBoundingClientRect() + const isInViewPort = rect.top >= 65 && rect.bottom <= innerHeight activeLink.classList.add('active') marker.value.style.top = activeLink.offsetTop + 39 + 'px' marker.value.style.opacity = '1' + if (asideContainer && !isInViewPort) { + asideContainer.scrollTop = offsetTop + } } else { marker.value.style.top = '33px' marker.value.style.opacity = '0' + if (asideContainer) { + asideContainer.scrollTop = 0 + } } } }