Download_ __ _ __| |_ __ __ _ __ _ /\ \ \__| |_ __ ___ _ __ / _` | '__/ _` |/ _` |/ \/ / _` | '__/ _ \| '_ \ | (_| | | | (_| | (_| / /\ | (_| | | | (_) | |_) | \__,_|_| \__,_|\__, \_\ \/ \__,_|_| \___/| .__/ |___/ |_|
Download_ __ _ __| |_ __ __ _ __ _ /\ \ \__| |_ __ ___ _ __ / _` | '__/ _` |/ _` |/ \/ / _` | '__/ _ \| '_ \ | (_| | | | (_| | (_| / /\ | (_| | | | (_) | |_) | \__,_|_| \__,_|\__, \_\ \/ \__,_|_| \___/| .__/ |___/ |_|
dragNdrop was successfully tested on a wide range of browsers, it even works on ie5. On modern browsers dragNdrop uses hardware accelerated css by default which makes it hyper fast. Old Browsers? Don’t worry: it gracefully falls back to normal position manipulation if the browser does not support hardware accelerated css
Your time matters, so dragNdrop is super quick and easy to use. If you know the basics of javascript you're ready to rock.
You want your website to be loaded as fast as possible. So dragNdrop only weights ~3KB (1KB gzipped) which is an average of 0,00005s loadtime. You name it – it's nothing.
dragNdrop is published under the MIT license and completely free to use. Oh and it's Open Source as well, so you can make it even better.
Download dragNdrop (minified) and add it to your document:
That's it, you're ready to rock!
Of course you can also just include the function within your code to save a request
With NPM:With Bower:npm install --save-dev npm-dragndrop
bower install --save-dev dragNdrop
See the Pen dragNdrop simple example by Thibault Jan Beyer (@ThibaultJanBeyer) on CodePen.
See the Pen dragNdrop simple example by Thibault Jan Beyer (@ThibaultJanBeyer)on CodePen.
See the Pen dragNdrop with constraints example by Thibault Jan Beyer (@ThibaultJanBeyer) on CodePen.
See the Pen dragNdrop with dropElements example by Thibault Jan Beyer (@ThibaultJanBeyer) on CodePen.
See the Pen dragNdrop with callback example by Thibault Jan Beyer (@ThibaultJanBeyer) on CodePen.
var dnd = dragNdrop({ element: document.getElementById('element') }); // you can now use start(), pause(), stop(), etc. like so: dnd.pause() // will stop the current dragging process dnd.stop(); // will teardown/stop the whole functionality dnd.start(); // reset the functionality after a teardown
Property | Type | Use |
---|---|---|
element | single DOM element (node) | the element that will be draggable |
customStyles | false / true (boolean) | when set to true, no styles will be added by the plugin |
useTransform | true / false (boolean) | use hardware accelerated css (translate3d) or not (default: true) |
constraints | false / 'x' / 'y' / single DOM element (boolean/ string/ node) | constrain the element: 'x' = element can only be dragged on the x axis. 'y' = element can only be dragged on the y axis. DOM element = element can only be dragged within that container |
dropZones | false / array of DOM element(s) or css selector(s) (node(s)) | one or more drop-elements (where the element can be dropped into) |
callback | function | a callback function that gets fired when the element is dropped. |
event.property | Use |
---|---|
element | the element that was dropped |
customStyles | false / true |
useTransform | true / false |
constraints | false / 'x' / 'y' / single DOM element |
dropZones | As array of DOM elements containing all drop-zones where the element can be dropped into |
dropped | false = element was not dropped into a drop-container [node] = array of dom elements = drop-containers in which the element was dropped |
dragNdrop:start | user click/tap the element |
dragNdrop:drag | user moves the element |
dragNdrop:stop | user releases the element |
dragNdrop:dropped | element was dropped into drop-container |
.dragNdrop | on every draggable element |
.dragNdrop--start | on element click |
.dragNdrop--drag | on element drag |
.dragNdrop--stop | on element release |
.dragNdrop--dropped | on successful element drop into container |
.dragNdrop--dropable | on element that can be dropped into at least one container |
.dragNdrop__dropzone | on every dropZone |
.dragNdrop__dropzone--ready | on corresponding dropZone when element is dragged |
.dragNdrop__dropzone--dropped | on dropZone when an element is successfully dropped inside |