From 9d1fae876bbcf5c4c802c4605c224ab47d1dbfd7 Mon Sep 17 00:00:00 2001 From: yoma Date: Sat, 14 Jun 2025 10:35:54 +0900 Subject: [PATCH] Fix: scroll to .active with consistent offset logic --- quartz/components/scripts/explorer.inline.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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" + }) } }