ewizardjs-touch v1.4.5
Touch
This module is a set of additional events and properties to handle user interaction. Use this module in your components to work with UI events universally.
Installation
co module install --save cobalt/touch
Usage
var touch = require('touch');
API
events
(object) - is an object containing a set of read-only keys. The values of these properties are the names of user events depending on the device the script is running on.Properties:
* `start` - mousedown | touchstart * `move` - mousemove | touchmove * `end` - mouseup | touchend
isTouch
(boolean) -true
if the script is running on mobile device, otherwise -false
.getOriginalEvent(event)
- returns event object bound to a specific finger (event.changedTouches[0]
), in case the script is running on mobile device or event object itself.Example:
document.addEventListener(touch.events.start, function(event){ event = touch.getOriginalEvent(event); console.log(event.pageX); });
events.start
property is used in this example to handlemousedown
andtouchstart
events simultaneously, depending on the platform.getOriginalEvent
function is called in the event handler to work with the actual event object.init(root)
- emulates events dispatching for root elements and all of it's children.root
- root element for events dispatching.
Events
swipeleft
- is triggered when the user presses down and swipes over an element in the left directionswiperight
- is triggered when the user presses down and swipes over an element in the right directionswipeup
- is triggered when the user presses down and swipes over an element upwardswipedown
- is triggered when the user presses down and swipes over an element downwardtap
- is triggered when the user touches the screen (it is fired beforeclick
)hold
- is triggered when the user touches the screen and holds it for 500ms
6 years ago