drag-event-service
Register both mouse and touch event.
const events = {
start: ['mousedown', 'touchstart'],
move: ['mousemove', 'touchmove'],
end: ['mouseup', 'touchend'],
}
install
npm install drag-event-service
usage & api
import DragEventService from 'drag-event-service'
DragEventService.on(el, name, handler, {args, mouseArgs, touchArgs})
on(el, name, handler, {args, mouseArgs, touchArgs}); off(el, name, handler, {args, mouseArgs, touchArgs})
- args, mouseArgs and touchArgs should be Array
- The args will pass to addEventListener.
- mouseArgs will pass to mouse event.
- touchArgs will pass to touch event.
- handler(event, currentPosition). The second argument of handler is current position({x, y}).
example
DragEventService.on(document, 'start', (e, mouse) => ..., {touchArgs: [{passive: false}]})
DragEventService.on(document, 'move', (e, mouse) => ..., {touchArgs: [{passive: false}]})
DragEventService.on(document, 'end', (e, mouse) => ..., {touchArgs: [{passive: false}]})
const handler = (e, mouse) => ...
DragEventService.on(document, 'start', handler)
DragEventService.off(document, 'start', handler)