Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including touch-velocity with all npm packages installed. Try it out:

var touchVelocity = require("touch-velocity")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

touch-velocity v0.0.4

Calculates velocity


Calculate (nearly) instantaneous velocity for a thing. Things like touch or mouse events. Calculating the velocity by looking at the last two events is wildly inaccurate, since the time difference between the two events being fired is often < 1ms.

This library smooths that out a bit by calculating over the last 100ms.


  var Velocity = require('touch-velocity')
    , velocity = new Velocity
    , touchTarget = document.querySelector('#touch-target')
  touchTarget.addEventListener('touchmove', function(evt) {

  touchTarget.addEventListener('touchend', function(evt) {



Updates the current position of the thing whose velocity you are tracking. You should do this any time you know that the thing's position has changed i.e. a touch event.


Gets the (nearly) instantaneous velocity of the thing you're tracking.


  • Work with 2d, accept both x and y positions.
  • Accept event objects


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free