node package manager


A small interaction event unifiying library


An interaction unifying library.

Makes binding to dragging and moving events easier.

Allows easy handling of multi-touch interactions.

Get it:

npm install interact-js

Require it:

var interact = require('interact-js');

Use it:

interact.on('move', document.body, moveHandler);
interact.on('start', document.body, startHandler);
interact.on('drag', document.body, dragHandler);
interact.on('end', document.body, endHandler);
interact.on('cancel', document.body, cancelHandler);

mousedown and/or touchstart

A mousemove while the mouse button is pressed


A touchmove.

Usually a mousemove

This event is rarely used.

mouseup and/or touchend

The event was canceled.

This could happen if the user ALT+TAB's, or if a system prompt appears wile they are interacting with the UI.

Event handlers are passed an instance of Interaction.

interact.on('drag', document.body, function(interaction){

The Interaction instance is persisted throughout the lifecycle of a user interaction. This means you can safely store custom data on the interaction, and it will be available in every following stage of the interaction. For example, in 'start', you could attach some data, and that data will still be there on 'drag'.

An interaction has a number of properties and methods that can be helpful

Maps to event.preventDefault

Maps to event.stopPropagation

Often, touch browsers will report the element that was touchstarted, even after the user moves their finger off of that element

This is stupid.

getActualTarget will get the actual element that is under the users finger.

Returns the distance bewteen this interaction and the previous one.


// 12.5476

Returns the difference between this interaction and the previous one in x and y


// {x: 5, y: -3}

Returns the speed in pixels per second over the last two pixels


// 5.0193452

Returns the angle that the interaction is traveling at.


// 90

pass true to get much nicer results at low speeds. Interact will figure out a more useful angle based of previous moves, and the speed that the interaction is moving.


// 104.246342

Returns an array of all interactions that are currently active.


// [Interaction, Interaction, Interaction]

An array of all the previous moves AND drags associated with the interaction.

At 1000 moves, the head of the list will be culled.

If you need more, you can track them yourself :)

The angle between the last two points.

This value is simplistic, and will report hard 90 degree mutliples at low speeds, as the interaction moves between two pixels.

use getCurrentAngle(true) for nicer angles.