We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 97799db commit d632b9aCopy full SHA for d632b9a
src/js/01-nav.js
@@ -29,7 +29,15 @@
29
// Auto scroll the side nav to the current page's side nav link
30
const currentPageLink = sideNav.querySelector('.nav-link.current-page')
31
if (currentPageLink) {
32
- currentPageLink.scrollIntoView({ block: 'center' })
+ const sideNavRect = sideNav.getBoundingClientRect()
33
+ const currentPageLinkRect = currentPageLink.getBoundingClientRect()
34
+ const offsetTop = currentPageLinkRect.top - sideNavRect.top + sideNav.scrollTop
35
+ if (
36
+ currentPageLinkRect.top < sideNavRect.top ||
37
+ currentPageLinkRect.bottom > (sideNavRect.bottom - 160)
38
+ ) {
39
+ sideNav.scrollTop = offsetTop - (sideNav.clientHeight - 160) / 2 + currentPageLink.clientHeight / 2
40
+ }
41
}
42
43
0 commit comments