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 drag-stream with all npm packages installed. Try it out:

var dragStream = require("drag-stream")

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

drag-stream v0.0.3

streamable mouse drag data


A readable stream of drag data for an element.

var drag = require('../index')
  , el = document.getElementById('content')

  .on('data', function(data) {
    // data == {dx:int, dy:int, dt:int}
    through(function(data) {
      this.emit('data', [data.dx, data.dy, data.dt].join(', ')) 


require('drag-stream') -> drag(el)

drag(el) -> readable stream

The stream will emit data events between a mousedown on the target el and mouseup anywhere else on the page.

The data events take the form of an x-delta, y-delta, and time-delta.

When a drag is started, its time-delta will be 0 and its x and y deltas will be the screen offset of the initial mousedown event.


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