mirror of
https://git.sr.ht/~ashkeel/strimertul-website
synced 2024-11-21 21:22:21 +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();
|
toc.parentElement.remove();
|
||||||
} else {
|
} else {
|
||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
const filtered = entries.filter((i) => getId(i.target));
|
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) => {
|
filtered.forEach((entry) => {
|
||||||
const id = getId(entry.target);
|
const id = getId(entry.target);
|
||||||
if (id && entry.intersectionRatio > 0) {
|
|
||||||
toc.querySelector(`li.active`)?.classList.remove("active");
|
|
||||||
toc
|
toc
|
||||||
.querySelector(`li a[href="#${id}"]`)
|
.querySelector(`li a[href="#${id}"]`)
|
||||||
.parentElement.classList.add("active");
|
.parentElement.classList.add("active");
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Track all sections that have an `id` applied
|
// Track all sections that have an `id` applied
|
||||||
|
|
Loading…
Reference in a new issue