Skip to content

Commit 3327905

Browse files
committed
docs: Fix sidebar scroll behaviour
1 parent 887a66b commit 3327905

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

docs/_static/sidebar.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ class Sidebar {
7878
}
7979

8080
setActiveLink(section) {
81-
if (this.activeLink) {
81+
let sectionSelected = this.activeLink?.href.split('#')[1] === section?.id;
82+
if (this.activeLink && !sectionSelected) {
8283
this.activeLink.parentElement.classList.remove('active');
8384
}
84-
if (section) {
85+
86+
if (section && !sectionSelected) {
8587
this.activeLink = document.querySelector(`#sidebar a[href="#${section.id}"]`);
8688
if (this.activeLink) {
8789
let headingChildren = this.activeLink.parentElement.parentElement;
@@ -90,8 +92,18 @@ class Sidebar {
9092
if (heading && headingChildren.style.display === 'none') {
9193
this.activeLink = heading;
9294
}
95+
9396
this.activeLink.parentElement.classList.add('active');
94-
this.activeLink.parentElement.scrollIntoView({ block: 'nearest', inline: 'start' });
97+
//this.setTimeout = window.setTimeout.bind(window);
98+
//this.clearTimeout = window.clearTimeout.bind(window);
99+
let scrollToActiveLink = (activeLink) => {
100+
activeLink.parentElement.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: 'auto' });
101+
}
102+
setTimeout(
103+
scrollToActiveLink,
104+
200,
105+
this.activeLink
106+
);
95107
}
96108
}
97109
}

0 commit comments

Comments
 (0)