ewizardjs-touch

1.4.5 • Public • Published

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

  1. 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
    
  2. isTouch (boolean) - true if the script is running on mobile device, otherwise - false.

  3. 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 handle mousedown and touchstart events simultaneously, depending on the platform. getOriginalEvent function is called in the event handler to work with the actual event object.

  4. 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 direction
  • swiperight - is triggered when the user presses down and swipes over an element in the right direction
  • swipeup - is triggered when the user presses down and swipes over an element upward
  • swipedown - is triggered when the user presses down and swipes over an element downward
  • tap - is triggered when the user touches the screen (it is fired before click)
  • hold - is triggered when the user touches the screen and holds it for 500ms

Readme

Keywords

none

Package Sidebar

Install

npm i ewizardjs-touch

Weekly Downloads

0

Version

1.4.5

License

ISC

Unpacked Size

25 kB

Total Files

12

Last publish

Collaborators

  • deniszavadskiy