Skip to content

Fix scroll to page top #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/core/event/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down