Skip to content

Commit

Permalink
fix: scroll position issue, fixed #234
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Sep 7, 2017
1 parent e898350 commit 388ed3d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/event/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const nav = {}
let hoverOver = false
let scroller = null
let enableScrollEvent = true
let coverHeight = 0

function scrollTo (el) {
if (scroller) scroller.stop()
Expand All @@ -27,7 +28,7 @@ function highlight () {
const wrap = dom.find(sidebar, '.sidebar-nav')
let active = dom.find(sidebar, 'li.active')
const doc = document.documentElement
const top = doc && doc.scrollTop || document.body.scrollTop
const top = (doc && doc.scrollTop || document.body.scrollTop) - coverHeight
let last

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

export function scrollActiveSidebar (router) {
if (isMobile) return
const cover = dom.find('.cover.show')
coverHeight = cover ? cover.offsetHeight : 0


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

if (isMobile) return

dom.off('scroll', highlight)
dom.on('scroll', highlight)
dom.on(sidebar, 'mouseover', () => { hoverOver = true })
Expand Down

0 comments on commit 388ed3d

Please sign in to comment.