mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-19 10:54:06 -06:00
Fix: scroll to .active with consistent offset logic
This commit is contained in:
parent
cdd0be2aa8
commit
9d1fae876b
@ -223,8 +223,18 @@ async function setupExplorer(currentSlug: FullSlug) {
|
|||||||
} else {
|
} else {
|
||||||
// try to scroll to the active element if it exists
|
// try to scroll to the active element if it exists
|
||||||
const activeElement = explorerUl.querySelector(".active")
|
const activeElement = explorerUl.querySelector(".active")
|
||||||
if (activeElement) {
|
const scrollContainer = explorer.querySelector(".explorer-content ul")
|
||||||
activeElement.scrollIntoView({ behavior: "smooth" })
|
|
||||||
|
if (activeElement && scrollContainer) {
|
||||||
|
const offset =
|
||||||
|
activeElement.getBoundingClientRect().top -
|
||||||
|
scrollContainer.getBoundingClientRect().top +
|
||||||
|
scrollContainer.scrollTop
|
||||||
|
|
||||||
|
scrollContainer.scrollTo({
|
||||||
|
top: offset,
|
||||||
|
behavior: "smooth"
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user