Skip to content

How to get speed of Srcollbar #344

Answered by idiotWu
cpiocova asked this question in Q&A
Discussion options

You must be logged in to vote

Since the speed is given by

you need to record the last offsets and compare it with current ones.

Here is the implementation from the demo page:

scrollbar.addListener(() => {
let current = Date.now();
let offset = scrollbar.offset.y;
let duration = current - lastTime;
if (!duration || offset === lastOffset) return;
if (duration > 100) {
reduceAmount += (duration - 1);
duration -= (duration - 1);
}
let velocity = (offset - lastOffset) / duration;
lastTime = current;
lastOffset = offset;
records.push({
offset,
time: c…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by idiotWu
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #199 on June 10, 2021 16:56.