onSwipe

Type:Function
Status:stable
Since:1.0.0
Platform:js
@blackbyte.sugar.js.dom.on

Detect swipes gestures on touch devices.

Params

  1. $elm*-HTMLElement

    The HTMLElement on which to detect the swipe

  2. cb*-Function

    The function to call on swipe. The callback function has as parameter an object that containthe swipe direction like left, right, up and down

  3. settings{}Partial<TOnSwipeSettings>

    Some settings to configure your swipe detection

Example

import { onSwipe } from '@blackbyte/sugar/dom'
onSwipe($elm, (swipe) => {
  // check the swipe direction
  if (swipe.left) {
    // do something...
	 }
	 // support : left, right, up, down
	 // etc...
}, {
  threshold : 50
});

Settings

  1. threshold100Number

    The swipe threshold

Todo

  • enhance the typing of the callbacknormal
  • testsnormal