sortable-dnd
A JS Library for Drag and Drop, supports Sortable and Draggable
Usage
Install
npm install sortable-dnd --save
HTML
<ul id="group">
<li class="item">
<i id="handle" class="handle">drag me</i>
<p>1</p>
</li>
<li class="item">
<i id="handle" class="handle">drag me</i>
<p>2</p>
</li>
<li class="item">
<i id="handle" class="handle">drag me</i>
<p>3</p>
</li>
</ul>
JavaScript
import Sortable from 'sortable-dnd'
let sortable = new Sortable(
document.getElementById('group'),
{
draggable: '.item',
handle: '.handle',
}
)
Options
new Sortable(element, {
draggable: '',
handle: '',
group: '',
multiple: false,
selectHandle: '',
animation: 150,
chosenClass: '',
selectedClass: '',
ghostStyle: {},
ghostClass: '',
disabled: false,
autoScroll: true,
scrollThreshold: 55,
scrollSpeed: { x: 10, y: 10 },
delay: 0,
delayOnTouchOnly: false,
fallbackOnBody: false,
store: null,
swapOnDrop: true | (params) => boolean,
customGhost: (nodes) => {
},
onChoose: (params) => {
},
onUnchoose: () => {
},
onDrag: (params) => {
},
onMove: (params) => {
},
onDrop: (params) => {
},
onAdd: (params) => {
},
onRemove: (params) => {
},
onChange: (params) => {
},
onSelect: (params) => {
},
onDeselect: (params) => {
},
})
Group
group: 'name',
group: {
name: 'group',
put: true | false | ['foo', 'bar'],
pull: true | false | 'clone',
revertDrag: true | false,
}
Params
let {
from,
to,
node,
nodes,
clone,
clones,
target,
oldIndex,
newIndex,
event,
pullMode,
relative,
revertDrag,
backToOrigin,
} = params
Select
let {
event,
index,
node,
from,
} = select
Methods
let sortable = new Sortable(el);
sortable.destroy();
sortable.option(key, value?);
sortable.select(element);
sortable.deselect(element);
sortable.getSelectedElements();
Static Methods & Properties
import Sortable from 'sortable-dnd';
Sortable.create(el: HTMLElement, options: Options);
Sortable.get(el: HTMLElement);
Sortable.dragged;
Sortable.clone;
Sortable.ghost;
Sortable.active;
Utils
const { on, off, css, index, closest, getRect, toggleClass } = Sortable.utils;
on(el: HTMLElement, event: String, fn: Function);
off(el: HTMLElement, event: String, fn: Function);
css(el: HTMLElement, prop: String, value: String);
index(el: HTMLElement, selector: String);
closest(el: HTMLElement, selector: String, context: HTMLElement, includeContext: Boolean);
getRect(element: HTMLElement, relativeToContainingBlock: boolean, container: HTMLElement);
toggleClass(el: HTMLElement, name: String, state: Boolean);