Skip to content

Commit

Permalink
fix(event): scroll active sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 11, 2017
1 parent 3941304 commit 50f5fc2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 50f5fc2

Please sign in to comment.