Skip to content

Commit e4963c9

Browse files
authored
fix: Added support for active class on clicking the side tab items (#177)
* added support for active class on clicking the side tab items * implemented scrollspy for auto section update in sidebar
1 parent 1f1edc6 commit e4963c9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/js/app.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ const SpeedTest = {
5353

5454
// Initialize gauge
5555
ProgressGauge.init();
56+
57+
// Scrollspy: update active nav link based on which section is in view
58+
const sections = document.querySelectorAll('#wrapper > section[id]');
59+
const navLinks = document.querySelectorAll('#sidebar nav a');
60+
61+
const observer = new IntersectionObserver(entries => {
62+
entries.forEach(entry => {
63+
if (entry.isIntersecting) {
64+
navLinks.forEach(link => {
65+
link.classList.toggle('active', link.getAttribute('href') === '#' + entry.target.id);
66+
});
67+
}
68+
});
69+
}, { rootMargin: '-45% 0px -45% 0px', threshold: 0 });
70+
71+
sections.forEach(section => observer.observe(section));
5672
},
5773

5874
onPrivacyChange() {

0 commit comments

Comments
 (0)