Code Monkey home page Code Monkey logo

draggables-js's Introduction

About

Allows flexible and fast drag/drop functionality. Specifically designed to be performant in these situations:

  • Many draggables
  • Many droppables
  • Draggables and droppables are not fixed collections and may change at any time
  • Set of allowed droppables may change depending on what's being drug.

Compatability

Initially designed to use MooTools, but it can easily be adapted to use any other library or likely to be library agnostic.

Usage

All properties shown here are required.

var dragdrop = new Draggables({
   root: any Element that is the common ancestor of all the draggable and droppable elements.
   getDraggable: function(target){
      // This is called on every mouse event.
      // target is the element on which an event happened (mousedown, move, up, ...)
      // If target or one of it's ancestors is draggable, return the element that should be
      // draggable; otherwise, return null and no drag will happen.
   },
   getDroppable: function(target, draggable){
      // This is called while dragging, draggable is the element being drug.
      // target is the element on which an event happened (mousedown, move, up, ...)
      // if target or one of it's ancestors is a drop target, return the element that should
      // act as the drop target; otherwise, return null and no drop event will happen.
   }
);

Events

Draggables fires several events that you can listen to. All of these events have a single argument (event) which is the standard event object from the associated mouse or keyboard event. The event argument also has draggable and droppable properties which are set to the element being dragged and the element that is the current drop target respectively (if applicable)

  • dragStart -- Fired as soon as an element is drug more than 10 pixels
  • dragInto -- Fired while dragging when the mouse enters into a drop-target
  • dragOut -- Fired while dragging when the mouse exits a drop-target
  • dragSuccess -- Fired while dragging when the mouse is released on a drop-target
  • dragFail -- Fired while dragging when the mouse is released on an non-drop-target
  • dragFinish -- Fired after dropFail and dropSuccess, always fires once for every dragStart

CSS Classes

To make drag and drop styling of UI elements easier, the class dragOver is added to the element returned from getDroppable while the mouse is over it during a drag event. You can use this to highlight that an area is a valid drop-target.

draggables-js's People

Contributors

danielbeardsley avatar

Stargazers

Corey Farwell avatar

Watchers

Corey Farwell avatar  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.