Skip to content

Tankōbon / lib/wheel-pager / createWheelPager

Function: createWheelPager() ​

createWheelPager(): (deltaY, now) => -1 | 0 | 1

Defined in: lib/wheel-pager.ts:28

Turns a stream of wheel events into at most one page turn per gesture.

A trackpad swipe (macOS especially) isn't one event: it's dozens, and once the finger lifts the OS keeps emitting decaying "inertia" events for a second or two. A fixed cooldown can't cover that without also making a plain mouse wheel sluggish, so a gesture is instead considered over only once the stream goes quiet for QUIET_MS — however long the inertia lasts. The one exception is a new swipe started while the previous one's inertia is still fading: inertia only ever decays, so a delta that suddenly jumps well above the previous one is a finger pushing again, and starts a new gesture.

Returns the step for each event: 1 (forward, deltaY > 0), -1 (backward) or 0.

Returns ​

(deltaY, now) => -1 | 0 | 1