Fix: scroll to .active with consistent offset logic

This commit is contained in:
yoma 2025-06-14 10:35:54 +09:00
parent cdd0be2aa8
commit 9d1fae876b

View File

@ -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"
})
}
}