Skip to content
Open
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
33 changes: 24 additions & 9 deletions src/core/event/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@ function scrollTo(el, offset = 0) {
}

enableScrollEvent = false;
scroller = new Tweezer({
start: window.pageYOffset,
end:
Math.round(el.getBoundingClientRect().top) + window.pageYOffset - offset,
duration: 500,
})
.on('tick', v => window.scrollTo(0, v))
.on('done', () => {
const scrollEnd =
Math.round(el.getBoundingClientRect().top) + window.pageYOffset - offset;
const reduceMotion = window.matchMedia(
'(prefers-reduced-motion: reduce)'
).matches;

if (reduceMotion) {
// User wants reduced motion: scroll instantly
setTimeout(() => {
window.scrollTo(0, scrollEnd);
enableScrollEvent = true;
scroller = null;
});
} else {
// Scroll smoothly
scroller = new Tweezer({
start: window.pageYOffset,
end: scrollEnd,
duration: 500,
})
.begin();
.on('tick', v => window.scrollTo(0, v))
.on('done', () => {
enableScrollEvent = true;
scroller = null;
})
.begin();
}
}

function highlight(path) {
Expand Down