Skip to content

Commit

Permalink
feat: accelerate scrollTo speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tidyzq committed Oct 13, 2022
1 parent 346ae64 commit 9336098
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/component/recycleScroller/recycleScroller.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
if (avoidRefresh) {
avoidRefresh = false;
} else {
await new Promise(resolve => setTimeout(resolve, 0))
await new Promise((resolve) => setTimeout(resolve, 0));
refresh(items, pos, viewportHeight, false);
}
Expand Down Expand Up @@ -467,10 +467,21 @@
const touchTracker = new TouchTracker(scrollHandler);
export const handler = {
scrollTo: (index: number, duration?: number) => {
scrollTo: (index: number) => {
const itemPos = topMap[Math.max(0, Math.min(items.length - 1, index))];
const scrollPos = Math.min(getScrollExtent(), itemPos);
const maxDuration = 500;
const minPixelsPerSecond = 2000;
const duration = Math.min(
Math.floor(
(maxDuration * Math.abs(scrollHandler.getPosition() - scrollPos)) /
minPixelsPerSecond
),
maxDuration
);
scrollHandler.scrollTo(scrollPos, duration);
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/log/log.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
};
export const scrollToTop = () => {
scrollerHandler.scrollTo(0, 500);
scrollerHandler.scrollTo(0);
};
export const scrollToBottom = () => {
scrollerHandler.scrollTo(logList.length - 1, 500);
scrollerHandler.scrollTo(logList.length - 1);
};
export const options: IVConsoleTabOptions = {
Expand Down

0 comments on commit 9336098

Please sign in to comment.