Squashed 'themes/codex/' content from commit da2d16a
git-subtree-dir: themes/codex git-subtree-split: da2d16a4f95fc37e71548dfc139d51e22ebb09bd
This commit is contained in:
17
static/js/table-of-contents.js
Normal file
17
static/js/table-of-contents.js
Normal file
@@ -0,0 +1,17 @@
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const observer = new IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
const id = entry.target.getAttribute('id');
|
||||
if (entry.intersectionRatio > 0) {
|
||||
document.querySelector(`#TableOfContents ul li a[href="#${id}"]`).classList.add('active');
|
||||
} else {
|
||||
document.querySelector(`#TableOfContents ul li a[href="#${id}"]`).classList.remove('active');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Track all headers that have an `id` applied
|
||||
document.querySelectorAll('article h3[id], article h2[id]').forEach((section) => {
|
||||
observer.observe(section);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user