mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 06:24:22 +02:00
fix(toc): Fixed headers in second ToC element not highlight-able
This commit is contained in:
parent
f70e562432
commit
2119025513
@ -1,13 +1,13 @@
|
|||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const slug = entry.target.id
|
const slug = entry.target.id
|
||||||
const tocEntryElement = document.querySelector(`a[data-for="${slug}"]`)
|
const tocEntryElements = document.querySelectorAll(`a[data-for="${slug}"]`)
|
||||||
const windowHeight = entry.rootBounds?.height
|
const windowHeight = entry.rootBounds?.height
|
||||||
if (windowHeight && tocEntryElement) {
|
if (windowHeight && tocEntryElements.length > 0) {
|
||||||
if (entry.boundingClientRect.y < windowHeight) {
|
if (entry.boundingClientRect.y < windowHeight) {
|
||||||
tocEntryElement.classList.add("in-view")
|
tocEntryElements.forEach((tocEntryElement) => tocEntryElement.classList.add("in-view"))
|
||||||
} else {
|
} else {
|
||||||
tocEntryElement.classList.remove("in-view")
|
tocEntryElements.forEach((tocEntryElement) => tocEntryElement.classList.remove("in-view"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user