Touch and pen
A finger or a pen drags with pointer events: the item stays in its list, dimmed, while a copy of it follows the
pointer. On a touch screen, rest a finger on an item for a moment (TouchDelay, 200 ms) to pick it
up - a quick swipe still scrolls the page. Escape, or the system taking the pointer over, puts the item back.
Long press
Apples
Bread
Coffee
Dates
Eggs
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Handle, at once
☰Flour
☰Grapes
☰Honey
☰Ice
☰Jam
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Mouse too (ForceFallback)
Kale
Lemons
Milk
Nuts
Oats
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Long press: Apples, Bread, Coffee, Dates, Eggs
Handle: Flour, Grapes, Honey, Ice, Jam
Mouse too: Kale, Lemons, Milk, Nuts, Oats
Try it
-
On a phone or a tablet, swipe across Long press: the page scrolls. Rest a finger on an item
until it lifts, then drag it. Raise
TouchDelayfor a longer press. -
Raise
Delayand drag an item of the same list with the mouse: the press has to be held that long before the item follows. Move more thanDelayTolerancepixels before then, and that press drags nothing - on a touch screen, it scrolls the page instead. -
In Handle, at once, a finger on ☰ drags straight away: the handle has
touch-action: none, so the browser does not scroll from it, andTouchDelay="0". The rest of the row still scrolls the page. -
Drag an item of Mouse too with the mouse: with
ForceFallbackthe mouse drags like a finger, with the same preview instead of the browser's drag image. Press Escape mid-drag: the item goes back.
How it works
-
A mouse drags with the browser's own HTML5 drag and drop, as SortableJS does on the desktop. A finger or a pen
drags with pointer events instead, which works the same in every browser and web view, whether or not it
supports HTML5 drag and drop on touch. Both feed the same hit test and raise the same events, with
Inputsaying which it was. -
Once a finger drags an item the page does not scroll under it. Near an edge the drag scrolls the list, a panel
around it, or the page (
Scroll) - the large list page shows it. - Escape, a system gesture that takes the pointer over (
pointercancel), or leaving the page cancels a pointer drag and puts everything back. - The click a browser sends after a press is swallowed after a drag, so dropping an item does not also click it. A press on a control inside an item - a button, a link, an input - is left to the control.
-
The preview is a copy of the item placed above the page, with the
DragClassclass (bit-bortable-drag):--bit-bortable-drag-opacityand--bit-bortable-drag-shadowrestyle it, and the styling page passes a class of its own.
Parameters on this page
| Parameter | Default | What it does |
|---|---|---|
TouchDelay | 200 | How long (ms) a finger must rest on an item before it drags it, so a swipe over the list still scrolls. |
Delay | 0 | The same for the mouse and a pen (SortableJS delay). |
DelayTolerance | 5 | How far (px) the pointer may move while a delay runs; further, and the press is a scroll or a click. |
ForceFallback | false | The mouse drags like a finger, with pointer events and the preview: for a preview of your own style, or a web view without HTML5 drag and drop. |
DragClass | bit-bortable-drag | The class of the preview that follows a finger, a pen or a ForceFallback mouse. |
Handle | With touch-action: none on the handle and TouchDelay="0", a handle that drags at once. |