Code Monkey home page Code Monkey logo

zepto.dragdrop.js's Introduction

build status

zepto.dragdrop.js

Micro (only 4kb) drag & drop library for Zepto with touch and mouse events.

Install

<script src="zepto.dragdrop.min.js"></script>

##Simple Usage

###drag

dragEl.draggable();

###drop

dropEl.droppable();

Callbacks

###drag Drag supports three callbacks: start, drag, and stop. Start is fired at the start of the drag; drag during the drag; and stop when dragging stops.

dragEl.draggable({
  start: function (e, dragEl) {
    // your code here
  },
  drag: function (e, dragEl) {
    // your code here
  },
  stop: function (e, dragEl) {
    // your code here
  }
});

###drop At the moment drop supports one callback drop which fires when draggable element is dropped into droppable element. Drop callback can be used to validate a drop action by returning true - successful drop or false - unsuccessful drop.

dragEl.draggable({
  drop: function (e, dragEl, dropEl, pos) {
     // your code here
     return true;
  }
});

Events

###drag

It's possible to bind to three different events draggable:start, draggable:drag and draggable:stop emitted by draggable.

dragEl.on('draggable:start', function () {
  // your code goes here
});

###drop

Droppable emits one event droppable:drop when element is successfully dropped.

Options

###drag

####selector (class name)

Delegates to elements defined by selector instead of the main object. This is useful if you have a lot of draggable elements. Instead of binding to each element you can setup draggable to their parent and delegate to dragging elements by providing selector.

####context

Changes context in which callbacks will be executed.

####revert

When set to true draggable element goes back to its starting position in case when drop fails.

###drop

####context

Changes context in which callbacks will be executed.

##License:

(The MIT License)

zepto.dragdrop.js's People

Contributors

mkuklis avatar

Watchers

James Cloos avatar Matias Nahuel Améndola 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.