sortable-dnd
A JS Library for Drag and Drop, supports Sortable-Draggable and Virtual-List
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,
swapOnDrop: true,
customGhost: (nodes) => {
},
onDrag: ({ from, event }) => {
},
onMove: ({ from, event }) => {
},
onDrop: ({ from, to, changed, event }) => {
},
onAdd: ({ from, to, event }) => {
},
onRemove: ({ from, to, event }) => {
},
onChange: ({ from, to, event }) => {
},
onSelect: (params) => {
},
onDeselect: (params) => {
},
})
Group
new Sortable(el, {
...,
group: 'name'
})
new Sortable(el, {
...,
group: {
name: 'group',
put: true | false | ['foo', 'bar'],
pull: true | false | 'clone',
revertClone: true | false,
}
})
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.ghost;
Sortable.active;
Utils
const { on, off, css, index, closest, getOffset, 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);
getOffset(element: HTMLElement, parentEl: HTMLElement);
toggleClass(el: HTMLElement, name: String, state: Boolean);