X-TOUCH

Implement mobile click, long press, and direction sliding events for native DOM.

Installation

  • Install via npm or yarn:
npm install x-touch --save

Getting off

  • Reference using ES6:
import XTouch from 'x-touch';

const xTouch = new XTouch();
xTouch.init();

This project is packaged in rollup using UMD format, supports AMD, CommonJS, and script tags, [download source] (https://github.com/codexu/x-touch/tree/master/dist)

  • Bind the touch event for the DOM:
const root = document.getElementById('root');

root.xtouch('tap', function(status){
  // do someting!
})

Event Name

  • 'tap' <String> Click

  • 'longTap' <String> long press

  • 'swipUp' <String> swipe up

  • 'swipDown' <String> Swipe down

  • 'swipLeft' <String> swipe left

  • 'swipRight' <String> swipe right

Callback

  • this <Object> ` this points to the bound DOM.

  • status <Object> ` The parameters for this event.

Configuration

Pass parameters when initializing XTouch:

const config = {
  slideMin: 50,
  tapMin: 10,
  longTapTime: 300
}

const xTouch = new XTouch(config);

slideMin

50 <Number>

The minimum distance of the sliding event.

tapMin

10 <Number>

Click on the maximum distance.

longTapTime

300 <Number>

Long press the shortest time.