Skip to content

Commit 388ed3d

Browse files
committed
fix: scroll position issue, fixed #234
1 parent e898350 commit 388ed3d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/core/event/scroll.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const nav = {}
66
let hoverOver = false
77
let scroller = null
88
let enableScrollEvent = true
9+
let coverHeight = 0
910

1011
function scrollTo (el) {
1112
if (scroller) scroller.stop()
@@ -27,7 +28,7 @@ function highlight () {
2728
const wrap = dom.find(sidebar, '.sidebar-nav')
2829
let active = dom.find(sidebar, 'li.active')
2930
const doc = document.documentElement
30-
const top = doc && doc.scrollTop || document.body.scrollTop
31+
const top = (doc && doc.scrollTop || document.body.scrollTop) - coverHeight
3132
let last
3233

3334
for (let i = 0, len = anchors.length; i < len; i += 1) {
@@ -71,7 +72,9 @@ function highlight () {
7172
}
7273

7374
export function scrollActiveSidebar (router) {
74-
if (isMobile) return
75+
const cover = dom.find('.cover.show')
76+
coverHeight = cover ? cover.offsetHeight : 0
77+
7578

7679
const sidebar = dom.getNode('.sidebar')
7780
const lis = dom.findAll(sidebar, 'li')
@@ -89,6 +92,8 @@ export function scrollActiveSidebar (router) {
8992
if (href) nav[decodeURIComponent(href)] = li
9093
}
9194

95+
if (isMobile) return
96+
9297
dom.off('scroll', highlight)
9398
dom.on('scroll', highlight)
9499
dom.on(sidebar, 'mouseover', () => { hoverOver = true })

0 commit comments

Comments
 (0)