From 50f5fc2b224859c413b372a0ae63a8dc917dd082 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 11 Feb 2017 09:22:39 +0800 Subject: [PATCH] fix(event): scroll active sidebar --- src/event.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/event.js b/src/event.js index 64585bdc1..72130cc2b 100644 --- a/src/event.js +++ b/src/event.js @@ -10,6 +10,7 @@ export function scrollActiveSidebar () { let hoveredOverSidebar = false const anchors = document.querySelectorAll('.anchor') const sidebar = document.querySelector('.sidebar') + const sidebarContainer = sidebar.querySelector('.sidebar-nav') const sidebarHeight = sidebar.clientHeight const nav = {} @@ -57,12 +58,12 @@ export function scrollActiveSidebar () { const currentPageOffset = 0 const currentActiveOffset = active.offsetTop + active.clientHeight + 40 const currentActiveIsInView = ( - active.offsetTop >= sidebar.scrollTop && - currentActiveOffset <= sidebar.scrollTop + sidebarHeight + active.offsetTop >= sidebarContainer.scrollTop && + currentActiveOffset <= sidebarContainer.scrollTop + sidebarHeight ) const linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight const newScrollTop = currentActiveIsInView - ? sidebar.scrollTop + ? sidebarContainer.scrollTop : linkNotFurtherThanSidebarHeight ? currentPageOffset : currentActiveOffset - sidebarHeight