diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index 762d949f7..28e54daec 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -15,7 +15,7 @@ function scrollTo(el) { enableScrollEvent = false scroller = new Tweezer({ start: window.pageYOffset, - end: el.getBoundingClientRect().top + window.pageYOffset, + end: el ? el.getBoundingClientRect().top + window.pageYOffset : 0, duration: 500 }) .on('tick', v => window.scrollTo(0, v)) @@ -124,18 +124,19 @@ export function scrollActiveSidebar(router) { } export function scrollIntoView(path, id) { - if (!id) { - return - } + var sidebar = dom.getNode('.sidebar'); + var active = dom.find(sidebar, 'li.active'); + active && active.classList.remove('active'); - const section = dom.find('#' + id) - section && scrollTo(section) + if (!id) { + scrollTo(null); + } else { + var section = dom.find('#' + id); + section && scrollTo(section); - const li = nav[getNavKey(path, id)] - const sidebar = dom.getNode('.sidebar') - const active = dom.find(sidebar, 'li.active') - active && active.classList.remove('active') - li && li.classList.add('active') + var li = nav[getNavKey(path, id)]; + li && li.classList.add('active'); + } } const scrollEl = dom.$.scrollingElement || dom.$.documentElement