interactjs

popular js
Drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+)
Version 1.10.27 License MIT
Keywords
interact.jsdraggabledroppabledragdropdrag and dropresizetouchmulti-touchgesturesnapinertiagridautoscrollSVG
INSTALL
Type:
Version:
- Static
- Latest Patch
- Latest Minor
- Latest Major
- 1.10.27
- 1.10.26
- 1.10.25
- 1.10.24
- 1.10.23
- 1.10.22
- 1.10.21
- 1.10.20
- 1.10.19
- 1.10.18
- 1.10.17
- 1.10.16
- 1.10.15
- 1.10.14
- 1.10.13
- 1.10.12
- 1.10.11
- 1.10.10
- 1.10.9
- 1.10.8
- 1.10.7
- 1.10.6
- 1.10.5
- 1.10.4
- 1.10.3
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.22
- 1.9.21
- 1.9.20
- 1.9.19
- 1.9.18
- 1.9.17
- 1.9.16
- 1.9.15
- 1.9.14
- 1.9.13
- 1.9.12
- 1.9.11
- 1.9.10
- 1.9.9
- 1.9.8
- 1.9.7
- 1.9.6
- 1.9.5
- 1.9.4
- 1.9.3
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.14
- 1.4.13
- 1.4.12
- 1.4.11
- 1.4.10
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.9
- 1.2.8
- 1.2.7
- 1.8.0-rc.3
- 1.8.0-rc.2
- 1.8.0-rc.1
- 1.8.0-rc.0
- 1.8.0-alpha.7
- 1.8.0-alpha.6
- 1.8.0-alpha.5
- 1.8.0-alpha.4
- 1.8.0-alpha.3
- 1.8.0-alpha.2
- 1.8.0-alpha.1
- 1.8.0-alpha.0
- 1.6.1-0
- 1.4.0-rc.13
- 1.4.0-rc.12
- 1.4.0-rc.11
- 1.4.0-rc.10
- 1.4.0-rc.9
- 1.4.0-rc.8
- 1.4.0-rc.7
- 1.4.0-rc.6
- 1.4.0-rc.5
- 1.4.0-rc.4
- 1.4.0-rc.3
- 1.4.0-rc.2
- 1.4.0-rc.1
- 1.4.0-rc.0
- 1.4.0-beta.4
- 1.4.0-beta.3
- 1.4.0-beta.2
- 1.4.0-beta.1
- 1.4.0-beta.0
- 1.4.0-alpha.33
- 1.4.0-alpha.32
- 1.4.0-alpha.31
- 1.4.0-alpha.30
- 1.4.0-alpha.29
- 1.4.0-alpha.28
- 1.4.0-alpha.27
- 1.4.0-alpha.26
- 1.4.0-alpha.25
- 1.4.0-alpha.24
- 1.4.0-alpha.23
- 1.4.0-alpha.22
- 1.4.0-alpha.21
- 1.4.0-alpha.20
- 1.4.0-alpha.19
- 1.4.0-alpha.18
- 1.4.0-alpha.17
- 1.4.0-alpha.16
- 1.4.0-alpha.15
- 1.4.0-alpha.14
- 1.4.0-alpha.13
- 1.4.0-alpha.12
- 1.4.0-alpha.10
- 1.4.0-alpha.9
- 1.4.0-alpha.8
- 1.4.0-alpha.7
- 1.4.0-alpha.6
- 1.4.0-alpha.5
- 1.4.0-alpha.4
- 1.4.0-alpha.3
- 1.4.0-alpha.2
- 1.4.0-alpha.1
- 1.4.0-alpha.0
- 1.3.0-rc.4
- 1.3.0-rc.3
- 1.3.0-rc.2
- 1.3.0-rc.1
- 1.3.0-rc.0
- 1.3.0-alpha.7
- 1.3.0-alpha.6
- 1.3.0-alpha.5
- 1.3.0-alpha.3
- 1.3.0-alpha.2
- 1.3.0-alpha.1
- 1.3.0-alpha.0
JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+).
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+:
yarn add interactjs
//= 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
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.