fix(event): scroll active sidebar
This commit is contained in:
parent
3941304fda
commit
50f5fc2b22
1 changed files with 4 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ export function scrollActiveSidebar () {
|
||||||
let hoveredOverSidebar = false
|
let hoveredOverSidebar = false
|
||||||
const anchors = document.querySelectorAll('.anchor')
|
const anchors = document.querySelectorAll('.anchor')
|
||||||
const sidebar = document.querySelector('.sidebar')
|
const sidebar = document.querySelector('.sidebar')
|
||||||
|
const sidebarContainer = sidebar.querySelector('.sidebar-nav')
|
||||||
const sidebarHeight = sidebar.clientHeight
|
const sidebarHeight = sidebar.clientHeight
|
||||||
|
|
||||||
const nav = {}
|
const nav = {}
|
||||||
|
|
@ -57,12 +58,12 @@ export function scrollActiveSidebar () {
|
||||||
const currentPageOffset = 0
|
const currentPageOffset = 0
|
||||||
const currentActiveOffset = active.offsetTop + active.clientHeight + 40
|
const currentActiveOffset = active.offsetTop + active.clientHeight + 40
|
||||||
const currentActiveIsInView = (
|
const currentActiveIsInView = (
|
||||||
active.offsetTop >= sidebar.scrollTop &&
|
active.offsetTop >= sidebarContainer.scrollTop &&
|
||||||
currentActiveOffset <= sidebar.scrollTop + sidebarHeight
|
currentActiveOffset <= sidebarContainer.scrollTop + sidebarHeight
|
||||||
)
|
)
|
||||||
const linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight
|
const linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight
|
||||||
const newScrollTop = currentActiveIsInView
|
const newScrollTop = currentActiveIsInView
|
||||||
? sidebar.scrollTop
|
? sidebarContainer.scrollTop
|
||||||
: linkNotFurtherThanSidebarHeight
|
: linkNotFurtherThanSidebarHeight
|
||||||
? currentPageOffset
|
? currentPageOffset
|
||||||
: currentActiveOffset - sidebarHeight
|
: currentActiveOffset - sidebarHeight
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue