Algorithm to implement kinetic scrolling

Viewed 21174

What are some good algorithms for creating a kinetic scrolling implementation? The feature would be tested on a custom UI list. While I am targeting mobile devices (those that do not have this feature built-in), any algorithm or code example from different programming field may also suit.

6 Answers

I searched a lot. Combined it all together i made my solution.

  1. While pointer down you should calculate difference in pixels btw each call onTouchMove handler. On touch end save this value in some variable, lets call it diffPx for example.
  2. Use requestAnimationFrame for continious momentum scrolling. On each frame scroll your container by diffPx =* 0.95 as long as diffPx would not reach some limit value(I used 0.25).
  3. One important limitation. Do step 2 only if diffPx on pointer up more than limit value(I used 5px).

https://developer.mozilla.org/ru/docs/Web/API/window/requestAnimationFrame

Related