diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index 9c8341169..7d3eae354 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -223,8 +223,18 @@ async function setupExplorer(currentSlug: FullSlug) { } else { // try to scroll to the active element if it exists const activeElement = explorerUl.querySelector(".active") - if (activeElement) { - activeElement.scrollIntoView({ behavior: "smooth" }) + const scrollContainer = explorer.querySelector(".explorer-content ul") + + if (activeElement && scrollContainer) { + const offset = + activeElement.getBoundingClientRect().top - + scrollContainer.getBoundingClientRect().top + + scrollContainer.scrollTop + + scrollContainer.scrollTo({ + top: offset, + behavior: "smooth" + }) } }