Skip to content

Commit 50f5fc2

Browse files
committed
fix(event): scroll active sidebar
1 parent 3941304 commit 50f5fc2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/event.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function scrollActiveSidebar () {
1010
let hoveredOverSidebar = false
1111
const anchors = document.querySelectorAll('.anchor')
1212
const sidebar = document.querySelector('.sidebar')
13+
const sidebarContainer = sidebar.querySelector('.sidebar-nav')
1314
const sidebarHeight = sidebar.clientHeight
1415

1516
const nav = {}
@@ -57,12 +58,12 @@ export function scrollActiveSidebar () {
5758
const currentPageOffset = 0
5859
const currentActiveOffset = active.offsetTop + active.clientHeight + 40
5960
const currentActiveIsInView = (
60-
active.offsetTop >= sidebar.scrollTop &&
61-
currentActiveOffset <= sidebar.scrollTop + sidebarHeight
61+
active.offsetTop >= sidebarContainer.scrollTop &&
62+
currentActiveOffset <= sidebarContainer.scrollTop + sidebarHeight
6263
)
6364
const linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight
6465
const newScrollTop = currentActiveIsInView
65-
? sidebar.scrollTop
66+
? sidebarContainer.scrollTop
6667
: linkNotFurtherThanSidebarHeight
6768
? currentPageOffset
6869
: currentActiveOffset - sidebarHeight

0 commit comments

Comments
 (0)