mirror of
https://git.sr.ht/~ashkeel/strimertul-website
synced 2024-11-19 21:12:20 +00:00
glitchier but nicer toc
This commit is contained in:
parent
3ec4a8df68
commit
a0fc21db39
1 changed files with 9 additions and 7 deletions
|
@ -14,16 +14,18 @@ if (toc) {
|
|||
toc.parentElement.remove();
|
||||
} else {
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
const filtered = entries.filter((i) => getId(i.target));
|
||||
filtered.forEach((entry) => {
|
||||
const id = getId(entry.target);
|
||||
if (id && entry.intersectionRatio > 0) {
|
||||
toc.querySelector(`li.active`)?.classList.remove("active");
|
||||
const filtered = entries.filter(
|
||||
(i) => getId(i.target) && i.intersectionRatio > 0
|
||||
);
|
||||
if (filtered.length > 0) {
|
||||
toc.querySelector(`li.active`)?.classList.remove("active");
|
||||
filtered.forEach((entry) => {
|
||||
const id = getId(entry.target);
|
||||
toc
|
||||
.querySelector(`li a[href="#${id}"]`)
|
||||
.parentElement.classList.add("active");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Track all sections that have an `id` applied
|
||||
|
|
Loading…
Reference in a new issue