Usage
First, create a DragDropManager instance to orchestrate the drag and drop system. Then use theDraggable
class to make elements draggable:
Handles
By default, the entire element can be used to initiate dragging. You can restrict dragging to a specific handle element:Types
You can assign types to draggable elements to restrict which droppable targets they can be dropped on:Feedback
You can customize how the element behaves while being dragged using thefeedback
option:
'default'
: The original element moves with the drag (best for most cases)'clone'
: A copy of the element stays in place while the original moves (good for drag-to-copy)'move'
: The element moves without a placeholder (minimal visual feedback)'none'
: No visual feedback (useful for custom drag overlays)
API Reference
Arguments
TheDraggable
class accepts the following arguments:
A unique identifier for this draggable element within the same drag and drop context provider.
The DOM element to make draggable. While not required in the constructor, it must be set to enable dragging.
Optionally specify a drag handle element. If not provided, the entire element will be draggable. See drag handles.
Optionally assign a type to restrict which droppable targets can accept this element. See types.
Specify how the element should behave while being dragged. See feedback.
Set to
true
to temporarily prevent dragging this element.Optional data to associate with this draggable element, available in event handlers.
This is an advanced feature and should not need to be used by most consumers.
destroy()
method of this instance.Properties
TheDraggable
instance provides these key properties:
id
: The unique identifierelement
: The main DOM elementhandle
: The drag handle element (if specified)type
: The assigned typedisabled
: Whether dragging is disabledisDragging
: Whether this element is currently being draggedisDropping
: Whether this element is being dropped
Methods
register()
: Register this draggable with the managerunregister()
: Remove this draggable from the managerdestroy()
: Clean up this draggable instance and remove all listeners