@dflex/draggable v3.10.6
Installation
npm install @dflex/draggableAPI
DFlex Draggable depends on three principles to achieve DOM interactivity:
- Register element in the store.
- Start dragging when mouse is down.
- End dragging to release element when mouse is up.
import { store, Draggable } from "@dflex/draggable";Register element
Each element should be registered in draggable store in order to be dragged later.
store.register(id: string);Create dragging instance
The dragging instance should be created when onmousedown is fired. So you
initialized the element before start dragging.
const dflexDraggable = new Draggable(id, clickCoordinates);id: stringregistered element-id in the store.coordinate: AxesPointis an object with{x: number, y: number}contains the coordinates of the
Start dragging
dflexDraggable.dragAt(x, y);x: numberis event.clientX, the horizontal click coordinate.y: numberis event.clientY, the vertical click coordinate.
End dragging
dflexDraggable.endDragging();Cleanup element
It's necessary to cleanup the element from store when the element won't be used or will be removed/unmounted from the DOM to prevent memory leaks.
store.unregister(id);id: stringregistered element-id.
Documentation 📖
For documentation, more information about DFlex and a live demo, be sure to visit the DFlex website https://www.dflex.dev/
License 🤝
DFlex is MIT License.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago