node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey »




(demo) - (source)

Physics for a touch-based scroll panel. Assumes a single dimension but could easily be extended to two or more.

Works best with scroll panes that have a fixed bounding region and need to "bounce" on either end. Can also "dip" into the cell edges (for example: carousels, list views, grids).

Makes no assumptions about the method of input or render engine (Canvas/DOM/WebGL/etc) but works well alongside touches. Simple example:

var scroller = require('touch-scroll-physics')({
    cellSize: 100,   //size of the content 
    viewSize: 400    //size of the viewport / clip region  
//tick the scroller  
function render(dt) {
//and hook up mouse to scroller start(x) / move(x) / end(x)  

See test.js for a more complete example with cells.


Run the demo here or build it yourself like so:

git clone
cd touch-scroll-physics
npm install
npm start

Then open localhost:9966. You can enter npm run build to build the distribution bundle.



scroller = ScrollPhysics([opt])

Creates a new scroller with the given options.

  • cellSize the size of each cell (default zero)
  • viewSize the size of your viewport (default zero)
  • totalCells total number of cells (default 1)
  • gutterSize the size of the gutter (default 1/4 of viewSize)
  • dipToClosestCell whether to smoothly snap to the edge of each cell (default false)

In the case of arbitrary scrolling (no "pages") you will typically just use a totalCells of 1 with the content size for cellSize.


Called to initiate a scroll event with the given value (e.g. X mouse position).


Called to signal a move event (e.g. mouse move X).


Called to end the scroll state at the given position (e.g. mouse up at X).


The value of the scroller. Typically when rendering you would translate content by the negative of this.


The current momentum for the scroller. May be useful for triggering events on swipe.


MIT, see for details.