Skip to content

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
Handle, at once
☰Flour
☰Grapes
☰Honey
☰Ice
☰Jam
Mouse too (ForceFallback)
Kale
Lemons
Milk
Nuts
Oats

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 TouchDelay for a longer press.
  • Raise Delay and drag an item of the same list with the mouse: the press has to be held that long before the item follows. Move more than DelayTolerance pixels 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, and TouchDelay="0". The rest of the row still scrolls the page.
  • Drag an item of Mouse too with the mouse: with ForceFallback the 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 Input saying 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 DragClass class (bit-bortable-drag): --bit-bortable-drag-opacity and --bit-bortable-drag-shadow restyle it, and the styling page passes a class of its own.

Parameters on this page

ParameterDefaultWhat it does
TouchDelay200How long (ms) a finger must rest on an item before it drags it, so a swipe over the list still scrolls.
Delay0The same for the mouse and a pen (SortableJS delay).
DelayTolerance5How far (px) the pointer may move while a delay runs; further, and the press is a scroll or a click.
ForceFallbackfalseThe 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.
DragClassbit-bortable-dragThe class of the preview that follows a finger, a pen or a ForceFallback mouse.
HandleWith touch-action: none on the handle and TouchDelay="0", a handle that drags at once.
An unhandled error has occurred. Reload 🗙