Skip to content

Commit

Permalink
fix: 修复pageScrollTo方法在h5下可能造成卡顿问题(raxjs#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuew2020 committed Nov 22, 2022
1 parent a728605 commit 1c99341
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/packages/interactive/pageScrollTo/src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export default normalize((options: Options) => {
// Scroll distance per 1ms
const speed = (scrollTop - top) / duration;

let nextTop = top;

const handleScroll = (startTime: number) => {
requestAnimationFrame(() => {
const cost = Date.now() - startTime;
Expand All @@ -59,8 +61,7 @@ export default normalize((options: Options) => {
return;
}

top = rootElement.scrollTop;
let nextTop = top + cost * speed;
nextTop = nextTop + cost * speed;
if ((speed > 0 && nextTop > scrollTop) || (speed < 0 && nextTop < scrollTop)) {
nextTop = scrollTop;
}
Expand Down

0 comments on commit 1c99341

Please sign in to comment.