interactjs
Drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE8+)
Last updated 8 years ago by taye .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install interactjs 
SYNC missed versions from official npm registry.

interact.js

JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+).

Gitter jsDelivr Build Status

Features include:

  • inertia and snapping
  • multi-touch, simultaneous interactions
  • cross browser and device, supporting the desktop and mobile versions of Chrome, Firefox and Opera as well as Internet Explorer 9+
  • interaction with SVG elements
  • being standalone and customizable
  • not modifying the DOM except to change the cursor (but you can disable that)

Installation

  • npm: npm install interactjs
  • jsDelivr CDN: <script src="https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js"></script>
  • unpkg CDN: <script src="https://unpkg.com/interactjs/dist/interact.min.js"></script>
  • Rails 5.1+:
    1. yarn add interactjs
    2. //= require interactjs/interact
  • Webjars SBT/Play 2: libraryDependencies ++= Seq("org.webjars.npm" % "interactjs" % version)

Typescript definitions

The project is written in Typescript and the npm package includes the type definitions, but if you need the typings alone, you can install them with:

npm install --save-dev @interactjs/types

Documentation

http://interactjs.io/docs

Example

var pixelSize = 16;

interact('.rainbow-pixel-canvas')
  .origin('self')
  .draggable({
    modifiers: [
      interact.modifiers.snap({
        // snap to the corners of a grid
        targets: [
          interact.snappers.grid({ x: pixelSize, y: pixelSize }),
        ],
      })
    ],
    listeners: {
      // draw colored squares on move
      move: function (event) {
        var context = event.target.getContext('2d'),
            // calculate the angle of the drag direction
            dragAngle = 180 * Math.atan2(event.dx, event.dy) / Math.PI;

        // set color based on drag angle and speed
        context.fillStyle = 'hsl(' + dragAngle + ', 86%, '
                            + (30 + Math.min(event.speed / 1000, 1) * 50) + '%)';

        // draw squares
        context.fillRect(event.pageX - pixelSize / 2, event.pageY - pixelSize / 2,
                         pixelSize, pixelSize);
      }
    }
  })
  // clear the canvas on doubletap
  .on('doubletap', function (event) {
    var context = event.target.getContext('2d');

    context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  });

  function resizeCanvases () {
    [].forEach.call(document.querySelectorAll('.rainbow-pixel-canvas'), function (canvas) {
      canvas.width = document.body.clientWidth;
      canvas.height = window.innerHeight * 0.7;
    });
  }

  // interact.js can also add DOM event listeners
  interact(document).on('DOMContentLoaded', resizeCanvases);
  interact(window).on('resize', resizeCanvases);

See the above code in action at https://codepen.io/taye/pen/tCKAm

License

interact.js is released under the MIT License.

Current Tags

  • 1.10.27                                ...           latest (8 months ago)
  • 1.8.3                                ...           next (5 years ago)

170 Versions

  • 1.10.27                                ...           8 months ago
  • 1.10.26                                ...           a year ago
  • 1.10.25                                ...           a year ago
  • 1.10.24                                ...           a year ago
  • 1.10.23                                ...           a year ago
  • 1.10.22                                ...           a year ago
  • 1.10.21                                ...           a year ago
  • 1.10.20                                ...           a year ago
  • 1.10.19                                ...           a year ago
  • 1.10.18                                ...           a year ago
  • 1.10.17                                ...           2 years ago
  • 1.10.16                                ...           2 years ago
  • 1.10.15                                ...           2 years ago
  • 1.10.14                                ...           2 years ago
  • 1.10.13                                ...           2 years ago
  • 1.10.12                                ...           2 years ago
  • 1.10.11                                ...           4 years ago
  • 1.10.10                                ...           4 years ago
  • 1.10.9                                ...           4 years ago
  • 1.10.8                                ...           4 years ago
  • 1.10.7                                ...           4 years ago
  • 1.10.6                                ...           4 years ago
  • 1.10.5                                ...           4 years ago
  • 1.10.4                                ...           4 years ago
  • 1.10.3                                ...           4 years ago
  • 1.10.2                                ...           4 years ago
  • 1.10.1                                ...           4 years ago
  • 1.10.0                                ...           4 years ago
  • 1.9.22                                ...           4 years ago
  • 1.9.21                                ...           4 years ago
  • 1.9.20                                ...           4 years ago
  • 1.9.19                                ...           4 years ago
  • 1.9.18                                ...           4 years ago
  • 1.9.17                                ...           4 years ago
  • 1.9.16                                ...           4 years ago
  • 1.9.15                                ...           4 years ago
  • 1.9.14                                ...           5 years ago
  • 1.9.13                                ...           5 years ago
  • 1.9.12                                ...           5 years ago
  • 1.9.11                                ...           5 years ago
  • 1.9.10                                ...           5 years ago
  • 1.9.9                                ...           5 years ago
  • 1.9.8                                ...           5 years ago
  • 1.9.7                                ...           5 years ago
  • 1.9.6                                ...           5 years ago
  • 1.9.5                                ...           5 years ago
  • 1.9.4                                ...           5 years ago
  • 1.9.3                                ...           5 years ago
  • 1.9.2                                ...           5 years ago
  • 1.9.1                                ...           5 years ago
  • 1.9.0                                ...           5 years ago
  • 1.8.5                                ...           5 years ago
  • 1.8.4                                ...           5 years ago
  • 1.8.3                                ...           5 years ago
  • 1.8.2                                ...           5 years ago
  • 1.8.1                                ...           5 years ago
  • 1.8.0                                ...           5 years ago
  • 1.8.0-rc.3                                ...           5 years ago
  • 1.8.0-rc.2                                ...           5 years ago
  • 1.8.0-rc.1                                ...           5 years ago
  • 1.8.0-rc.0                                ...           5 years ago
  • 1.8.0-alpha.7                                ...           5 years ago
  • 1.7.3                                ...           5 years ago
  • 1.8.0-alpha.6                                ...           5 years ago
  • 1.8.0-alpha.5                                ...           5 years ago
  • 1.8.0-alpha.4                                ...           5 years ago
  • 1.8.0-alpha.3                                ...           5 years ago
  • 1.8.0-alpha.2                                ...           5 years ago
  • 1.8.0-alpha.1                                ...           5 years ago
  • 1.7.2                                ...           5 years ago
  • 1.7.1                                ...           5 years ago
  • 1.8.0-alpha.0                                ...           5 years ago
  • 1.7.0                                ...           5 years ago
  • 1.6.3                                ...           5 years ago
  • 1.6.2                                ...           5 years ago
  • 1.6.1                                ...           5 years ago
  • 1.6.1-0                                ...           5 years ago
  • 1.6.0                                ...           5 years ago
  • 1.5.4                                ...           5 years ago
  • 1.5.3                                ...           5 years ago
  • 1.5.2                                ...           5 years ago
  • 1.5.1                                ...           5 years ago
  • 1.5.0                                ...           5 years ago
  • 1.4.14                                ...           5 years ago
  • 1.4.13                                ...           5 years ago
  • 1.4.12                                ...           5 years ago
  • 1.4.11                                ...           5 years ago
  • 1.4.10                                ...           5 years ago
  • 1.4.9                                ...           5 years ago
  • 1.4.8                                ...           5 years ago
  • 1.4.7                                ...           5 years ago
  • 1.4.6                                ...           5 years ago
  • 1.4.5                                ...           5 years ago
  • 1.4.4                                ...           5 years ago
  • 1.4.3                                ...           5 years ago
  • 1.4.2                                ...           5 years ago
  • 1.4.1                                ...           6 years ago
  • 1.4.0                                ...           6 years ago
  • 1.4.0-rc.13                                ...           6 years ago
  • 1.4.0-rc.12                                ...           6 years ago
  • 1.4.0-rc.11                                ...           6 years ago
  • 1.4.0-rc.10                                ...           6 years ago
  • 1.4.0-rc.9                                ...           6 years ago
  • 1.4.0-rc.8                                ...           6 years ago
  • 1.4.0-rc.7                                ...           6 years ago
  • 1.4.0-rc.6                                ...           6 years ago
  • 1.4.0-rc.5                                ...           6 years ago
  • 1.4.0-rc.4                                ...           6 years ago
  • 1.4.0-rc.3                                ...           6 years ago
  • 1.4.0-rc.2                                ...           6 years ago
  • 1.4.0-rc.1                                ...           6 years ago
  • 1.4.0-rc.0                                ...           6 years ago
  • 1.4.0-beta.4                                ...           6 years ago
  • 1.4.0-beta.3                                ...           6 years ago
  • 1.4.0-beta.2                                ...           6 years ago
  • 1.4.0-beta.1                                ...           6 years ago
  • 1.4.0-beta.0                                ...           6 years ago
  • 1.4.0-alpha.33                                ...           6 years ago
  • 1.4.0-alpha.32                                ...           6 years ago
  • 1.4.0-alpha.31                                ...           6 years ago
  • 1.4.0-alpha.30                                ...           6 years ago
  • 1.4.0-alpha.29                                ...           6 years ago
  • 1.4.0-alpha.28                                ...           6 years ago
  • 1.4.0-alpha.27                                ...           6 years ago
  • 1.4.0-alpha.26                                ...           6 years ago
  • 1.4.0-alpha.25                                ...           6 years ago
  • 1.4.0-alpha.24                                ...           6 years ago
  • 1.4.0-alpha.23                                ...           6 years ago
  • 1.4.0-alpha.22                                ...           6 years ago
  • 1.4.0-alpha.21                                ...           6 years ago
  • 1.4.0-alpha.20                                ...           6 years ago
  • 1.4.0-alpha.19                                ...           6 years ago
  • 1.4.0-alpha.18                                ...           6 years ago
  • 1.4.0-alpha.17                                ...           6 years ago
  • 1.4.0-alpha.16                                ...           6 years ago
  • 1.4.0-alpha.15                                ...           6 years ago
  • 1.4.0-alpha.14                                ...           6 years ago
  • 1.4.0-alpha.13                                ...           6 years ago
  • 1.4.0-alpha.12                                ...           6 years ago
  • 1.4.0-alpha.10                                ...           6 years ago
  • 1.4.0-alpha.9                                ...           6 years ago
  • 1.4.0-alpha.8                                ...           6 years ago
  • 1.4.0-alpha.7                                ...           6 years ago
  • 1.4.0-alpha.6                                ...           6 years ago
  • 1.3.4                                ...           7 years ago
  • 1.4.0-alpha.5                                ...           7 years ago
  • 1.4.0-alpha.4                                ...           7 years ago
  • 1.4.0-alpha.3                                ...           7 years ago
  • 1.4.0-alpha.2                                ...           7 years ago
  • 1.4.0-alpha.1                                ...           7 years ago
  • 1.4.0-alpha.0                                ...           7 years ago
  • 1.3.3                                ...           7 years ago
  • 1.3.2                                ...           7 years ago
  • 1.3.1                                ...           7 years ago
  • 1.3.0                                ...           7 years ago
  • 1.3.0-rc.4                                ...           7 years ago
  • 1.3.0-rc.3                                ...           7 years ago
  • 1.3.0-rc.2                                ...           7 years ago
  • 1.3.0-rc.1                                ...           7 years ago
  • 1.3.0-rc.0                                ...           7 years ago
  • 1.3.0-alpha.7                                ...           7 years ago
  • 1.3.0-alpha.6                                ...           7 years ago
  • 1.3.0-alpha.5                                ...           7 years ago
  • 1.2.9                                ...           7 years ago
  • 1.3.0-alpha.3                                ...           7 years ago
  • 1.3.0-alpha.2                                ...           7 years ago
  • 1.3.0-alpha.1                                ...           8 years ago
  • 1.3.0-alpha.0                                ...           8 years ago
  • 1.2.8                                ...           8 years ago
  • 1.2.7                                ...           8 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE