• Stars
    star
    1,161
  • Rank 40,194 (Top 0.8 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

👋 Touch gesture library, 1kb~5kb, compatible with PC / mobile

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.

Gesture Name Describe
pan pan Triggered continuously while dragging
panstart drag to start
panmove dragging
panstart Drag to stop (off screen)
panup / pandown / panright / panleft Drag events in different directions
press press Press
press Press release (off screen)
tap tap Click, No problem with 300ms delay
swipe swipe Swipe
swipeup / swipedown / swiperight / swipeleft Swipe in different directions
pinch pinch Zoom
pinchstart Zoom start
pinchmove Zooming
pinchend Zoom ends (off screen)
pinchin Zoom in
pinchout Zoom out
rotate rotate Rotating, 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

name type describe
name String Gesture recognizer name, such as: pan/tap/swipe, etc.
type String Event 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
phase String Current touch state: start / move / end / cancel Corresponding: first touch / move on the screen / leave the screen / abnormally leave the "can anyTouch" element
x Number Current contact center x coordinate
y Number Current contact center y coordinate
deltaX Number The x-axis offset distance of the current contact and the previous contact
deltaY Number The y-axis offset distance of the current contact and the previous contact
displacementX Number The x displacement of the current contact and the starting contact (vector)
displacementY Number The y displacement of the current contact and the starting contact (vector)
distanceX Number absolute value of displacementX
distanceY Number absolute value of displacementY
distance Number The distance between the current contact and the starting contact (scalar)
deltaTime Number The difference between the current time and the initial touch time
velocityX Number The moving speed of the contact on the X axis
velocityY Number The moving speed of the contact on the Y axis
direction Number The direction of the front contact and the current contact can be understood as the instantaneous direction
angle Number When multi-touch, the rotation angle between the starting contact and the current contact
deltaAngle Number When multi-touch, the rotation angle between the front contact and the current contact
scale Number When multi-touch, the zoom ratio of the starting touch point and the current touch point
deltaScale Number When multi-touch, the zoom ratio between the previous touch point and the current touch point
maxPointLength Number The maximum number of contacts that have occurred in the current identification cycle
isStart Boolean Whether 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
isEnd Boolean Whether the current recognition cycle is over
target EventTarget The element to which the event is bound
targets EventTarget[] For multiple touches, each target in touches will be stored
currentTarget EventTarget The element that actually triggered the bound event
nativeEvent TouchEvent native 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

More Repositories

1

any-rule

🦕 常用正则大全, 支持web / vscode / idea / Alfred Workflow多平台
TypeScript
8,497
star
2

be-full

🛰 浏览器全屏 / full screen
TypeScript
153
star
3

vue-create-root

🍭 不到1kb的小工具, 把组件变成this.$xxx命令.
TypeScript
142
star
4

any-ui

❄️ 一个移动端组件库
Vue
63
star
5

5a.css

❄️ 一个css组件库
SCSS
60
star
6

my

🌱常用函数, 都小于1k, 方便看源码学ts
TypeScript
59
star
7

any-scroll

🚀 模拟scrollview, 支持pc/移动端, 让实现Tab/Slider等组件轻而易举.
TypeScript
48
star
8

any-type

一键 JSON 转 Typescript 类型.
TypeScript
31
star
9

crud-vue

Vue
29
star
10

Notes

🚀 笔记
25
star
11

v-use-axios

在vue3中更聪明的使用axios.
TypeScript
14
star
12

ts-log-cn

🚀 ts 更新日志速读, 持续更新...
12
star
13

any-event

🍰 不到1k, 一个mini的事件管理器, 希望能在您的代码中做一块砖
TypeScript
12
star
14

ts-class

ts课程, 为了升职加薪, (๑•̀ㅂ•́)و✧加油
JavaScript
11
star
15

arr2tree

🌲 数组转树
TypeScript
9
star
16

be-mock

一键假数据
Vue
9
star
17

v-admin

Vue
6
star
18

webpack-mulit-page-start

🍞基于webpack4的多页模板
JavaScript
4
star
19

vue3-start

vue3课程源码
Vue
4
star
20

any86

4
star
21

log

根据git记录生成日志
JavaScript
3
star
22

vue-error

常见vue3报错解决
2
star
23

383514580.github.io

用vue2做的blog例子
JavaScript
2
star
24

lose-weight

为了健康, 减肥!
2
star
25

e-admin

xxxx
JavaScript
2
star
26

watch-wheel

🖱️ 监控鼠标滚动
TypeScript
1
star
27

5a-weapp

基于5a.css样式的微信小程序组件库
JavaScript
1
star
28

s6n

Vue
1
star
29

atom-ripple

atom-ripple
JavaScript
1
star
30

threeJsPractice

⚡ 学习three.js的练习
JavaScript
1
star
31

three-start

TypeScript
1
star
32

iChat

socket.io练习
JavaScript
1
star
33

photo-touch

支持手势的图片处理插件
Vue
1
star
34

sleepq123

1
star
35

vue-auth-gate

TypeScript
1
star
36

md-api

生成简单的markdown格式的api文档
Vue
1
star
37

face

1
star
38

vue-book

vue-book
1
star
39

arPractice

https://383514580.github.io/arPractice/
Brainfuck
1
star
40

vue3-read-start

1
star
41

useful-utils

迁移到 => https://github.com/any86/6h
1
star
42

qk

快速获取dom和bom的位置和尺寸信息
1
star
43

studyPuppteer

JavaScript
1
star