Merge commit 'bfb1829a86a2bc1b595dad52a9d6dcfe80dd0679' as 'themes/codex'
This commit is contained in:
17
themes/codex/static/js/table-of-contents.js
Normal file
17
themes/codex/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