Gathering detailed insights and metrics for drag-drop-plus
Gathering detailed insights and metrics for drag-drop-plus
Gathering detailed insights and metrics for drag-drop-plus
Gathering detailed insights and metrics for drag-drop-plus
vue-draggable-plus
Universal Drag-and-Drop Component Supporting both Vue 3 and Vue 2
ng-drag-drop-plus

react-form-builder-plus
A complete form builder for react.
react-drag-sortable-plus
React drag & drop highly customizable sortable list component
Drag any object in DOM and drop it anywhere in DOM. Works well with Mouse, Touch and Keyboard events.
npm install drag-drop-plus
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
25 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Feb 24, 2025
Latest Version
1.0.4
Package Id
drag-drop-plus@1.0.4
Unpacked Size
50.16 kB
Size
9.28 kB
File Count
5
NPM Version
8.18.0
Node Version
18.8.0
Published on
Jan 29, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
A JavaScript library for enabling drag and drop functionality on any elements in the DOM. This library also includes accessibility features, allowing users to drag and drop elements using only their keyboard.
The drag-drop-plus library is a powerful and easy to use tool that allows developers to easily add drag and drop functionality to their web projects. This library is designed to make it easy to add drag and drop functionality to any element in the DOM, while also providing accessibility options so users can drag and drop elements using only their keyboard.
Use this library if:
Include one of the following CDN link in your project. And create a new instance of the class.
1https://devashishp1999.github.io/drag-drop-plus/main.min.js
1<script src="CDN_LINK"></script> 2 3<script> 4 const draggable = new DragDrop(); 5</script>
Or Install with NPM:
1npm i drag-drop-plus
1import DragDrop from "drag-drop-plus"; 2 3const draggable = new DragDrop();
NOTE : The script needs an attribute of the element to make it draggable or a drop-zone. Default attributes are set for:
data-draggable
data-dropzone
Also you can set your custom Attributes
. To make an element droppable in specific drop-zone among multiple drop-zones.
To see elements in action, do not forget to add styles.
data-dragging-box
is the default attribute for the element while dragging. And the Element while dragging will always be aclone()
of the element you are dragging.
1.) Create an instance.
1const draggable = new DragDrop();
2.) Add required attributes to HTML Tags
1<!-- Tell script what to drag --> 2<span data-draggable> drag-box 1 </span> 3<span data-draggable> drag-box 2 </span> 4 5<!-- Tell script where to drop --> 6<div data-dropzone>drop-zone 1</div> 7<div data-dropzone>drop-zone 2</div> 8<div data-dropzone>drop-zone 3</div>
And DONE. Now, in this example, <span>
elements are draggable and you can drop them inside the <div>
elements.
setDragDropElements()
To create multiple draggable-boxes and specific drop-zones for them. Create multiple instances of the class and use setDragDropElements()
method.
1.) Create multiple instances.
1const draggable_1 = new DragDrop();
2const draggable_2 = new DragDrop();
3
4// 1st Drag-Drop Environment
5draggable_1.setDragDropElements({
6 boxAttr: "data-draggable-1",
7 dropboxAttr: "data-dropzone-1",
8 dragboxAttr: "data-dragging-box-1", // Attribute for the Element while dragging
9});
10
11// 2nd Drag-Drop Environment
12draggable_2.setDragDropElements({
13 boxAttr: "data-draggable-2",
14 dropboxAttr: "data-dropzone-2",
15 dragboxAttr: "data-dragging-box-2", // Attribute for the Element while dragging
16});
2.) Add required attributes to HTML Tags
1<!-- Draggable SET 1--> 2<span data-draggable-1> drag-box 1 </span> 3<span data-draggable-1> drag-box 1 </span> 4 5<!-- DropZone for SET 1 --> 6<div data-dropzone-1>drop-zone 1</div> 7<div data-dropzone-1>drop-zone 2</div> 8 9------------------------------------------ 10 11<!-- Draggable SET 2--> 12<span data-draggable-2> drag-box 2 </span> 13<span data-draggable-2> drag-box 2 </span> 14 15<!-- DropZone for SET 2 --> 16<div data-dropzone-2>drop-zone 1</div> 17<div data-dropzone-2>drop-zone 2</div>
Now the <span>
elements with data-draggable-1
attribute can only be dropped in the <div>
elements with the data-dropzone-1
attributes. And same for every new Attribute
you specify for a new Instance new DragDrop()
.
Move to a draggable element with TAB
key.
Press SPACE
key to select the focused draggable element.
To drop you have 2 options :
TAB
key to focus a dropzone
. And then press SPACE
key to drop on focused dropzone.Arrow Keys
to move the selected drag-box. And make its center inside your favourite dropzone. And then press SPACE
key to drop the element.The library is built with a number of abstracted methods, which make it easy for developers to customize the behavior of the drag and drop functionality to fit their specific needs.
1) draggingBox
: Reference of the HTMLElement being dragged. Read Only.
2) boxToDrag
: Reference of the HTMLElement to drag. Read Only.
Note : boxToDrag !== draggingBox
1const draggable = new DragDrop(); 2 3draggable.onDragStart = function () { 4 console.log(draggable.draggingBox); // HTMLElement user is dragging 5 console.log(draggable.boxToDrag); // HTMLElement that is selected to drag 6}; 7 8// There are more methods other than onDragStart(). See 'Methods' section
3) droppable
: Read Only.
1const draggable = new DragDrop(); 2 3draggable.onDrag = function () { 4 // Read Only property. 5 console.log(draggable.draggable); // Logs the Object on every Drag event 6}; 7/* 8Returned Object : 9{ 10 value: false, // If draggibg-box is over valid drop-zone or not. Default: false 11 dropbox: null, // Valid dropbox HTMLElement or Null/False. Default: null 12}; 13*/
It can be used to check, before droping or while dragging, if an element can be dropped or not. and get the drop-zone element. Can be helpful to style elements, also with the methods()
listed below.
1) setDragDropElements()
: Tells script the value of custom attributes.
Put the same attributes in your HTMLElements that you update via this method
1const draggable = new DragDrop();
2
3draggable.setDragDropElements({
4 boxAttr: "data-drag-this",
5 dropboxAttr: "data-drop-here",
6 dragboxAttr: "data-being-dragged", // Attribute for the Element while dragging
7});
2) addEventListners()
: Adds eventListners to drag-drop to the elements with the specified attributes. The class this function by default.
3) removeEventListners()
: Removes all the attached eventListners for the Drag-drop functionality from the elements with the attributes in that instance.
1const draggable_1 = new DragDrop(); 2const draggable_2 = new DragDrop(); 3 4draggable_1.removeEventListners(); 5draggable_1.addEventListners(); 6 7draggable_2.removeEventListners();
Methods to override : by default they are set to () => null
1) onDragStart()
: runs when selected a draggable-box
2) onDrag()
: runs when Dragging with mouse/ Touch/ KeyPresses
3) onKeyDrag()
: runs when Dragging with only KeyPress
4) onDragEnd()
: runs when mouse is released after dragging.
5) onDrop()
: runs when element dropped successfully
6) onTabKeypress()
: runs when hopping b/w drop-zones.
Override these methods, if you want to, as following:
1const draggable = new DragDrop();
2
3draggable.onDragStart = function () {
4 console.log(draggable.boxToDrag); // HTMLElement user selected to drag
5
6 /* Any thing you want to do onDragStart */
7};
8
9draggable.onDrag = function (event) {
10 console.log(draggable.draggingBox); // HTMLElement user is dragging
11 console.log(draggable.droppable);
12
13 console.log(event.type);
14 /* Any thing you want to do onDrag */
15};
16
17draggable.onDrop = function (event) {
18 console.log(draggable.droppable.dropbox) // HTMLElement where drag-box is dropped
19 console.log(event); // MouseEvent or KeyboardEvent
20 .
21 .
22 /* Any thing you want to do onDrop */
23};
24
25/* Other Methods */
If you liked this. Give this repo a ⭐ STAR ⭐
This library is released under the MIT license
No vulnerabilities found.
No security vulnerabilities found.