1.0.0 • Published 4 years ago

zbam v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

zbam

A tiny plugin for orchestrating drag/draw/swipe-like mouse/touch events, with tiny API. Event listeners are added to the window object, and element targeting is carried out with dragStartCondition setting.

Usage

Zbam can be installed with npm, by the following command:

npm install zbam

Importing by the default export is enough. Simply create instances as following:

import Zbam from 'zbam'

let instance = new Zbam({
  dragStart(event) {...},
  dragMove(event) {...},
  dragEnd(event) {...},
})

// Then remove event listeners with
instance.destroy()

API

OptionsTypeDescription
startDraggingAfterNumberSet a duration (in milliseconds) to differentiate pan from click. Pan class won't execute if the duration between mousedown/mouseup or touchstart/touchend is less than this duration.
dragStartConditionFunctionIs a function with event argument as the argument.
settingsObjectPassed directly to event listeners as the third argument. You can set passive: true if you want to create passive event listeners.
dragStartFunctionMain callback for drag start: runs on touchstart and mousedown
dragMoveFunctionMain callback for drag move: runs on touchmove and mousemove
dragEndFunctionMain callback for drag end: runs on touchend and mouseup

License

Licensed with the MIT License