1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul-website synced 2024-11-23 21:32:20 +00:00

glitchier but nicer toc

This commit is contained in:
Ash Keel 2023-03-01 14:20:15 +01:00
parent 3ec4a8df68
commit a0fc21db39
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E

View file

@ -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