About Draggable Mixin
This mixin adds drag gesture detection to any web component. It supports drag start, move, and end events with customizable thresholds. Perfect for creating draggable interfaces and interactive elements.
๐ก Tip: This mixin coordinates with other mixins using the PointerCoordinator, so it can work alongside SwipeableMixin without conflicts!
๐งช Simple Test
Try dragging this red box first to test basic functionality (use mouse on desktop or touch on mobile):
Simple Test Element
Drag this red box to test basic functionality (threshold: 5px)
๐ฏ Interactive Drag Demo
Try dragging the container below in different directions:
Drag Me!
Use mouse or touch to drag this element
โ๏ธ Drag Settings
๐ Drag History
๐จ Multiple Draggable Elements
Card 1
Drag to interact
Card 2
Different behavior
๐ค Mixin Coordination Demo
This element has both DraggableMixin and SwipeableMixin. Try dragging and swiping to see how they coordinate:
Drag + Swipe
Drag to move, swipe for quick gestures
๐ Reversed Order Coordination Demo
This element has SwipeableMixin as parent and DraggableMixin as child. Test if coordination works in reverse order:
Swipe + Drag (Reversed)
Swipe for quick gestures, drag to move
๐ Scroll Prevention Test
This area is scrollable. Try scrolling normally, then try dragging/swiping the colored boxes to see how scroll prevention works:
Scrollable content starts here...
Scroll down to see more content...
Test Area 1 - Draggable Element
Scroll prevention should activate when dragging
Test Area 2 - Swipeable Element
Scroll prevention should activate when swiping
Test Area 3 - Combined Element
Both gestures should work and prevent scrolling
More scrollable content...
Scroll up to see the test elements again...
โข Normal scrolling works when not interacting with mixins
โข Scroll prevention activates only when gestures are detected
โข Scroll prevention deactivates when gestures end
โข Multiple mixins coordinate through PointerCoordinator
๐ Implementation Guide
How to Use the Draggable Mixin:
1. Use the element: <draggable-mixin>...content...</draggable-mixin>
2. Set optional attributes: drag-threshold
3. Listen for events: dragstart
, dragmove
, dragend
โจ Features
What the Draggable Mixin Provides:
- Drag Detection: Detects when dragging starts, moves, and ends
- Customizable Threshold: Adjustable minimum distance to start dragging
- Direction Detection: Tracks drag direction (left, right, up, down)
- Event Dispatching: Automatically dispatches drag events
- Mixin Coordination: Works with other mixins using PointerCoordinator
- Performance Optimized: Efficient pointer event handling
- Easy Integration: Simple mixin pattern for any component