@@ -6,6 +6,7 @@ const nav = {}
6
6
let hoverOver = false
7
7
let scroller = null
8
8
let enableScrollEvent = true
9
+ let coverHeight = 0
9
10
10
11
function scrollTo ( el ) {
11
12
if ( scroller ) scroller . stop ( )
@@ -27,7 +28,7 @@ function highlight () {
27
28
const wrap = dom . find ( sidebar , '.sidebar-nav' )
28
29
let active = dom . find ( sidebar , 'li.active' )
29
30
const doc = document . documentElement
30
- const top = doc && doc . scrollTop || document . body . scrollTop
31
+ const top = ( doc && doc . scrollTop || document . body . scrollTop ) - coverHeight
31
32
let last
32
33
33
34
for ( let i = 0 , len = anchors . length ; i < len ; i += 1 ) {
@@ -71,7 +72,9 @@ function highlight () {
71
72
}
72
73
73
74
export function scrollActiveSidebar ( router ) {
74
- if ( isMobile ) return
75
+ const cover = dom . find ( '.cover.show' )
76
+ coverHeight = cover ? cover . offsetHeight : 0
77
+
75
78
76
79
const sidebar = dom . getNode ( '.sidebar' )
77
80
const lis = dom . findAll ( sidebar , 'li' )
@@ -89,6 +92,8 @@ export function scrollActiveSidebar (router) {
89
92
if ( href ) nav [ decodeURIComponent ( href ) ] = li
90
93
}
91
94
95
+ if ( isMobile ) return
96
+
92
97
dom . off ( 'scroll' , highlight )
93
98
dom . on ( 'scroll' , highlight )
94
99
dom . on ( sidebar , 'mouseover' , ( ) => { hoverOver = true } )
0 commit comments