GithubHelp home page GithubHelp logo

nvdnkpr / interact.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taye/interact.js

0.0 1.0 0.0 8.09 MB

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

Home Page: http://interactjs.io/

License: MIT License

JavaScript 97.79% TypeScript 1.39% Shell 0.82%

interact.js's Introduction

interact.js

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

Gitter Build Status Test Coverage

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

  • Bower: bower install interactjs
  • npm: npm install interactjs
  • Webjars SBT/Play 2: libraryDependencies ++= Seq("org.webjars.bower" % "interactjs" % version)
  • Direct download the latest version: http://interactjs.io/#download
    • Rails 4 app development (using Rails Asset Pipeline)
      • Download the file interact.js (development version) into a new sub-directory: vendor/assets/javascripts/interact
      • Add //= require interact/interact in app/assets/javascripts/application.js (above //= require_tree .)
      • Restart the Rails server
  • jsDelivr CDN: <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/interact.min.js"></script>
  • unpkG CDN: <script src="https://unpkg.com/[email protected]/dist/interact.min.js"></script>

Documentation

Visit http://interactjs.io/docs for the API documentation.

Example

var pixelSize = 16;

interact('.rainbow-pixel-canvas')
  .origin('self')
  .draggable({
    modifiers: [
      interact.modifiers.snap({
        targets: [ interact.snappers.grid({
          x: pixelSize, y: pixelSize
        }) ],
      }),
    ],
    // allow multiple drags on the same element
    maxPerElement: Infinity
  })
  // draw colored squares on move
  .on('dragmove', 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 http://codepen.io/taye/pen/YPyLxE

License

interact.js is released under the MIT License.

interact.js's People

Contributors

taye avatar stephen-james avatar horstvanbommel avatar coloz avatar stbaer avatar gdh1995 avatar losd avatar jdewit avatar danperkins avatar zbjornson avatar roboncode avatar nickez avatar lddubeau avatar noahlaux avatar pborreli avatar peterdavehello avatar eswat avatar ruathudo avatar stevewillard avatar tombyrer avatar tclift avatar tom-grove avatar tbekolay avatar veloce avatar afc163 avatar hauptmech avatar mortonfox avatar marian-r avatar ltfschoen avatar jonathanpicques avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.