ScrollBooster

Enjoyable content drag-to-scroll library

Mouse, touch, wheel and keys Inertia and rubber band TypeScript No dependencies 6.5 kB gzip

npm i scrollbooster

Two elements and one line

The viewport clips, the content moves inside it. Drag with a mouse or a finger, throw it, pull it past the edge, scroll with a wheel or a trackpad, Tab into it and use the arrow keys. Clicks on links and buttons still work, the click that ends a drag does not fire.

Every example below runs the code next to it.

index.html

Big picture

Both directions with inertia. Pull the picture past an edge: it resists more the further you pull and springs back on release. setPosition() starts from the middle once the image loads.

Images that load later
Paper lanterns over a street at night
picture.js

Wide table

scrollMode: 'native' moves the native scroll of the viewport, so the sticky header and first column, scrollbars and touch scrolling work as usual. axisLock keeps a drag on a row or a column. Checkboxes take clicks, a press on them does not drag.

Native scroll and dragging the whole page
table.js

Tabs

wheel: 'horizontal' turns the mouse wheel into horizontal scroll, the page takes over at the end of the strip. A click centers the tab with scrollIntoView(), a drag selects nothing.

tabs.js

Your own rendering

With scrollMode: 'none' ScrollBooster only computes the position, with inertia and bounce, and onUpdate draws it. Here each layer moves at its own depth.

parallax.js

More demos

Pages for every scenario, each scroller with its live state.