This package is a small utility that listens and composes mouse or touch events to dragging callbacks.
npm i start-drag
import { strtr } from 'start-drag';
element.addEventListener('mousedown', (event) => {
const destroy = startDrag(
event,
document.body,
(event: MouseEvent, x: number, y: number, relX: number, relY: number) => {
console.log(x, y, relX, relY);
},
(event: MouseEvent) => {
console.log('end');
},
);
// call destroy to stop listening
destroy();
});
MIT License