any86/any-touch

๐Ÿ‘‹ Touch gesture library, 1kb~5kb, compatible with PC / mobile

TypeScript

1,242

1,506 commits

updated Jan 9, 2026

See the code

README

any-touch NPM Version NPM Downloads size-image codecov CircleCI

gestures

  • Support PC/Mobile/WeChat applet.
  • 6 gesture recognizers are loaded by default, can also be loaded on demand, core 1kb, full 5kb.
  • No dependencies, not limited to Vue / React / Angular etc...

Language

ไธญๆ–‡ | English

Demo

QR Code

Simple

any-scroll

Install

npm i -S any-touch

CDN

<script src="https://unpkg.com/any-touch/dist/any-touch.umd.min.js"></script>
<script>
    console.log(AnyTouch.version); // 2.x.x
</script>

Directory

โšก Get Started

๐ŸŒฑ Vue & Directives

๐Ÿ€ WeChat applet

๐Ÿ“ Load on demand

๐ŸŒˆ Advanced

๐Ÿ’ก API

๐Ÿณ Q & A

Get Started

import AnyTouch from 'any-touch';

// monitored element
const el = document.getElementById('box');

// Start monitoring gesture changes on el
const at = new AnyTouch(el);

// The pan event fires when dragging
at.on('pan', (e) => {
    // e contains information such as displacement/velocity/direction
    console.log(e);
});

The pan here is called gesture event. e is the event object, which contains data such as "position/speed/zoom/angle",

๐Ÿ‘‹Gesture

Each state of the gesture corresponds to an event.

GestureNameDescribe
panpanTriggered continuously while dragging
panstartdrag to start
panmovedragging
panstartDrag to stop (off screen)
panup / pandown / panright / panleftDrag events in different directions
presspressPress
pressPress release (off screen)
taptapClick, No problem with 300ms delay
swipeswipeSwipe
swipeup / swipedown / swiperight / swipeleftSwipe in different directions
pinchpinchZoom
pinchstart Zoom start
pinchmove Zooming
pinchend Zoom ends (off screen)
pinchin Zoom in
pinchout Zoom out
rotaterotateRotating, include rotatestart and rotatemove and rotateend
rotatestart Start of rotation
rotatemove Rotating
rotateend End of rotation (off screen)

Combining events

You can listen to multiple events through the array, such as listening to panleft and panright at the same time, so that you can listen to "x-axis dragging".

at.on(['panleft', 'panright'], () => {
    console.log('Drag on the x-axis');
});

๐Ÿš€ back to directory

๐Ÿญ Event

When the event is triggered, data such as "position/speed/zoom/angle" can be obtained.

at.on('pan', (event) => {
    // event contains data such as speed/direction
});

event

nametypedescribe
nameStringGesture recognizer name, such as: pan/tap/swipe, etc.
typeStringEvent name, such as tap or panstart, etc., is larger than the name field, such as: when the type is panstart or panmove, and the name returns pan
phaseStringCurrent touch state: start / move / end / cancel Corresponding: first touch / move on the screen / leave the screen / abnormally leave the "can anyTouch" element
xNumberCurrent contact center x coordinate
yNumberCurrent contact center y coordinate
deltaXNumberThe x-axis offset distance of the current contact and the previous contact
deltaYNumberThe y-axis offset distance of the current contact and the previous contact
displacementXNumberThe x displacement of the current contact and the starting contact (vector)
displacementYNumberThe y displacement of the current contact and the starting contact (vector)
distanceXNumberabsolute value of displacementX
distanceYNumberabsolute value of displacementY
distanceNumberThe distance between the current contact and the starting contact (scalar)
deltaTimeNumberThe difference between the current time and the initial touch time
velocityXNumberThe moving speed of the contact on the X axis
velocityYNumberThe moving speed of the contact on the Y axis
directionNumberThe direction of the front contact and the current contact can be understood as the instantaneous direction
angleNumberWhen multi-touch, the rotation angle between the starting contact and the current contact
deltaAngleNumberWhen multi-touch, the rotation angle between the front contact and the current contact
scaleNumberWhen multi-touch, the zoom ratio of the starting touch point and the current touch point
deltaScaleNumberWhen multi-touch, the zoom ratio between the previous touch point and the current touch point
maxPointLengthNumberThe maximum number of contacts that have occurred in the current identification cycle
isStartBooleanWhether the current recognition cycle starts, the rule is that it is a cycle from touchstart->touchend, even if there is a multi-touch, if a point leaves, the current round of recognition ends
isEndBooleanWhether the current recognition cycle is over
targetEventTargetThe element to which the event is bound
targetsEventTarget[]For multiple touches, each target in touches will be stored
currentTargetEventTargetThe element that actually triggered the bound event
nativeEventTouchEventnative event object

๐Ÿš€ back to directory

Typescript

If the event function is bound in the vue template, the type of the event object cannot be deduced, so we need to manually annotate it ourselves.

<div @tap="onTap"></div>
// xxx.vue
import type { AnyTouchEvent } from 'any-touch';
function onTap(e: AnyTouchEvent) {
    // It can be correctly deduced that there is an x attribute on e
    console.log(e.x);
}

๐Ÿš€ back to directory

angular
drag
finger
gesture
javascript
mouse
pan
pinch
press
react
rotate
swipe
tap
touch
typescript
vanilla
vue

any86/any-touch

๐Ÿ‘‹ Touch gesture library, 1kb~5kb, compatible with PC / mobile

TypeScript

1,242

1,506 commits

updated Jan 9, 2026

See the code

README

any-touch NPM Version NPM Downloads size-image codecov CircleCI

gestures

  • Support PC/Mobile/WeChat applet.
  • 6 gesture recognizers are loaded by default, can also be loaded on demand, core 1kb, full 5kb.
  • No dependencies, not limited to Vue / React / Angular etc...

Language

ไธญๆ–‡ | English

Demo

QR Code

Simple

any-scroll

Install

npm i -S any-touch

CDN

<script src="https://unpkg.com/any-touch/dist/any-touch.umd.min.js"></script>
<script>
    console.log(AnyTouch.version); // 2.x.x
</script>

Directory

โšก Get Started

๐ŸŒฑ Vue & Directives

๐Ÿ€ WeChat applet

๐Ÿ“ Load on demand

๐ŸŒˆ Advanced

๐Ÿ’ก API

๐Ÿณ Q & A

Get Started

import AnyTouch from 'any-touch';

// monitored element
const el = document.getElementById('box');

// Start monitoring gesture changes on el
const at = new AnyTouch(el);

// The pan event fires when dragging
at.on('pan', (e) => {
    // e contains information such as displacement/velocity/direction
    console.log(e);
});

The pan here is called gesture event. e is the event object, which contains data such as "position/speed/zoom/angle",

๐Ÿ‘‹Gesture

Each state of the gesture corresponds to an event.

GestureNameDescribe
panpanTriggered continuously while dragging
panstartdrag to start
panmovedragging
panstartDrag to stop (off screen)
panup / pandown / panright / panleftDrag events in different directions
presspressPress
pressPress release (off screen)
taptapClick, No problem with 300ms delay
swipeswipeSwipe
swipeup / swipedown / swiperight / swipeleftSwipe in different directions
pinchpinchZoom
pinchstart Zoom start
pinchmove Zooming
pinchend Zoom ends (off screen)
pinchin Zoom in
pinchout Zoom out
rotaterotateRotating, include rotatestart and rotatemove and rotateend
rotatestart Start of rotation
rotatemove Rotating
rotateend End of rotation (off screen)

Combining events

You can listen to multiple events through the array, such as listening to panleft and panright at the same time, so that you can listen to "x-axis dragging".

at.on(['panleft', 'panright'], () => {
    console.log('Drag on the x-axis');
});

๐Ÿš€ back to directory

๐Ÿญ Event

When the event is triggered, data such as "position/speed/zoom/angle" can be obtained.

at.on('pan', (event) => {
    // event contains data such as speed/direction
});

event

nametypedescribe
nameStringGesture recognizer name, such as: pan/tap/swipe, etc.
typeStringEvent name, such as tap or panstart, etc., is larger than the name field, such as: when the type is panstart or panmove, and the name returns pan
phaseStringCurrent touch state: start / move / end / cancel Corresponding: first touch / move on the screen / leave the screen / abnormally leave the "can anyTouch" element
xNumberCurrent contact center x coordinate
yNumberCurrent contact center y coordinate
deltaXNumberThe x-axis offset distance of the current contact and the previous contact
deltaYNumberThe y-axis offset distance of the current contact and the previous contact
displacementXNumberThe x displacement of the current contact and the starting contact (vector)
displacementYNumberThe y displacement of the current contact and the starting contact (vector)
distanceXNumberabsolute value of displacementX
distanceYNumberabsolute value of displacementY
distanceNumberThe distance between the current contact and the starting contact (scalar)
deltaTimeNumberThe difference between the current time and the initial touch time
velocityXNumberThe moving speed of the contact on the X axis
velocityYNumberThe moving speed of the contact on the Y axis
directionNumberThe direction of the front contact and the current contact can be understood as the instantaneous direction
angleNumberWhen multi-touch, the rotation angle between the starting contact and the current contact
deltaAngleNumberWhen multi-touch, the rotation angle between the front contact and the current contact
scaleNumberWhen multi-touch, the zoom ratio of the starting touch point and the current touch point
deltaScaleNumberWhen multi-touch, the zoom ratio between the previous touch point and the current touch point
maxPointLengthNumberThe maximum number of contacts that have occurred in the current identification cycle
isStartBooleanWhether the current recognition cycle starts, the rule is that it is a cycle from touchstart->touchend, even if there is a multi-touch, if a point leaves, the current round of recognition ends
isEndBooleanWhether the current recognition cycle is over
targetEventTargetThe element to which the event is bound
targetsEventTarget[]For multiple touches, each target in touches will be stored
currentTargetEventTargetThe element that actually triggered the bound event
nativeEventTouchEventnative event object

๐Ÿš€ back to directory

Typescript

If the event function is bound in the vue template, the type of the event object cannot be deduced, so we need to manually annotate it ourselves.

<div @tap="onTap"></div>
// xxx.vue
import type { AnyTouchEvent } from 'any-touch';
function onTap(e: AnyTouchEvent) {
    // It can be correctly deduced that there is an x attribute on e
    console.log(e.x);
}

๐Ÿš€ back to directory

angular
drag
finger
gesture
javascript
mouse
pan
pinch
press
react
rotate
swipe
tap
touch
typescript
vanilla
vue

Project health

Overall

2.4/10

Maintained

0/10

Code review

0/10
OpenSSF Scorecard

Latest release

2.2.0 ยท May 24, 2022

Releases this year

0

Significant stargazers

Floyd Wang

67 followers ยท starred May 2020

qer

130 followers ยท starred Oct 2023

Liu Bo

237 followers ยท starred Mar 2020

Cloyd Lau

39 followers ยท starred Apr 2026