All Projects → any86 → Any Touch

any86 / Any Touch

Licence: mit
👋 手势库, 按需2kb~5kb, 兼容PC / 移动端

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Any Touch

React Cursor Position
A React component that decorates its children with mouse and touch coordinates relative to itself.
Stars: ✭ 136 (-76.01%)
Mutual labels:  mouse, tap, drag, touch, pan
gesto
You can set up drag, pinch events in any browser.
Stars: ✭ 47 (-91.71%)
Mutual labels:  touch, drag, mouse, gesture
gestures
A library for normalized events and gesture for desktop and mobile.
Stars: ✭ 31 (-94.53%)
Mutual labels:  tap, touch, swipe, gesture
Gesturerecognizerclosures
Closure support for handling gesture recognizers in Swift.
Stars: ✭ 84 (-85.19%)
Mutual labels:  tap, swipe, pan
Rxgesture
RxSwift reactive wrapper for view gestures
Stars: ✭ 1,069 (+88.54%)
Mutual labels:  swipe, gesture, pan
React Easy Swipe
Easy handler for common swipe operations
Stars: ✭ 85 (-85.01%)
Mutual labels:  mouse, swipe, touch
XamarinFormsGesture
Xamarin Form Gesture Effects
Stars: ✭ 85 (-85.01%)
Mutual labels:  tap, swipe, gesture
React Native Swipe Gestures
4-directional swipe gestures for react-native
Stars: ✭ 471 (-16.93%)
Mutual labels:  swipe, gesture, touch
React Event Components
🛰 A set of React components designed to handle global events (interval, keyboard, touch, mouse, etc)
Stars: ✭ 271 (-52.2%)
Mutual labels:  mouse, touch
Cupertino Pane
🎉📱Multi-functional panes and boards for next generation progressive applications
Stars: ✭ 267 (-52.91%)
Mutual labels:  swipe, touch
Sortable
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Stars: ✭ 23,641 (+4069.49%)
Mutual labels:  drag, touch
Recyclerviewevent
RecyclerView onItemClick、onItemLongClick、drag、swipe、divider、reuse disorder RecyclerView 梳理:点击&长按事件、分割线、拖曳排序、滑动删除、优雅解决 EditText 和 CheckBox 复用错乱问题
Stars: ✭ 265 (-53.26%)
Mutual labels:  swipe, drag
Hover On Touch
A pure Javascript Plugin for an alternative hover function that works on mobile and desktop devices. It triggers a hover css class on »Taphold« and goes to a possible link on »Tap«. It works with all html elements.
Stars: ✭ 256 (-54.85%)
Mutual labels:  tap, touch
Gnome Shell Extended Gestures
Better touchpad gesture handling for GNOME
Stars: ✭ 281 (-50.44%)
Mutual labels:  swipe, gesture
Pancake
Lightweight, Fast, Easy-to-use HTML5 2D game framework!
Stars: ✭ 79 (-86.07%)
Mutual labels:  touch, mouse
Flutter advanced networkimage
flutter advanced network image provider
Stars: ✭ 282 (-50.26%)
Mutual labels:  pan, rotate
Rotatable
Helper class to make any view rotatable
Stars: ✭ 295 (-47.97%)
Mutual labels:  swipe, rotate
subjx
Drag/Resize/Rotate Javascript library
Stars: ✭ 155 (-72.66%)
Mutual labels:  drag, rotate
Showtime
The easiest way to show off your iOS taps and gestures for demos and videos.
Stars: ✭ 281 (-50.44%)
Mutual labels:  tap, gesture
Alloyfinger
Super tiny size multi-touch gestures library for the web.    You can touch this →
Stars: ✭ 3,244 (+472.13%)
Mutual labels:  gesture, touch

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

6类手势

  • 支持PC 端 / 移动端 / 微信小程序.
  • 默认加载6个手势, 也可🤖按需加载手势, 核心2kb, 完整5kb.
  • 通过6类手势可以扩展出更多手势.

演示

查看二维码

直接访问

目录

⚡️ 快速开始

🌱 兼容vue语法

📱 支持微信小程序

🤖 按需加载

👋 还支持哪些手势?

💡 API & 高级技巧

🍭 事件对象(event)

❗️❗️❗️ 注意事项

安装

npm i -S any-touch

CDN

https://unpkg.com/any-touch/dist/any-touch.umd.min.js

快速开始

HTML中引入

<h1 id="box">hello world</h1>
<script src="https://unpkg.com/any-touch/dist/any-touch.umd.min.js"></script>
<script>
const el = document.getElementById('box');
const at = new AnyTouch(el);
at.on('tap', e => console.log('e包含位置等信息',e));
</script>

或者, 使用NPM

import AnyTouch from 'any-touch';
const el = document.getElementById('box');
const at = new AnyTouch(el);
at.on('pan', e => console.log('e包含位移/速度/方向等信息',e))

🚀 返回目录

兼容vue语法

<div 
    @tap="onTap" 
    @swipe="onSwipe" 
    @press="onPress" 
    @pan="onPan" 
    @pinch="onPinch" 
    @rotate="onRotate">
    <p>Hello any-touch</p>
</div>
import AnyTouch from 'any-touch';
export default {
    mounted() {
        // 没错, 就这2行
        const at= new AnyTouch(this.$el);
        this.$on('hook:destroyed', ()=>{at.destroy()});
    }
};

⚠️注意: @tap这种语法只能用在元素标签上, 而不能用在自定义组件标签上:

<!-- 有效 -->
<div @tap="onTap"></div>

<!-- 不生效, 监听不到tap -->
<my-component @tap="onTap"></my-component>

🚀 返回目录

支持微信小程序

由于小程序中没有dom元素的概念, 所以我们需要通过catchEvent方法手动接收touch事件的事件对象来进行识别!

<view 
  @touchstart="at.catchEvent"
  @touchmove="at.catchEvent"
  @touchend="at.catchEvent"
  @touchcancel="at.catchEvent">
</view>
const at = new AnyTouch()
{
    onload(){
        at.on('press', onPress);
    }
}

🚀 返回目录

按需加载

默认any-touch支持所有手势, 为了更小的体积, 提供了按需加载.

// 只加载pan识别器(拖拽)
import Core from '@any-touch/core';
import Pan from '@any-touch/pan';
// 使用Pan
const at = Core(el);
at.use(Pan);

// 拖拽
at.on('swipe', onSwipe);

⚠️ 注意: 执行npm i any-touch后, "@any-touch/core"和"@any-touch/xx手势"便已自动安装, 直接引入即可.

@any-touch/core

手势库的核心组件, 主要用来实现PC/移动端的兼容(查看更多).

@any-touch/xx手势

手势识别器均已做成独立的包, 从而实现按需加载.

名称 说明
@any-touch/tap 点击
@any-touch/pan 拖拽
@any-touch/swipe
@any-touch/press 按压
@any-touch/pinch 缩放
@any-touch/rotate 旋转

⚠️ 再次提示: 如果已安装"any-touch", 上面的包便也已经自动安装.

还支持哪些手势?

除了上面说的6大类手势外, 还细分了更多手势: |手势名|说明| |---|---| |pressup|按压松开| |panstart|拖拽开始| |panmove|拖拽中| |panend|拖拽结束| |pinchstart|缩放开始| |pinchmove|缩放中| |pinchend|缩放结束| |rotatestart|旋转开始| |rotatemove|旋转中| |rotateend|旋转结束|

at.on('panstart', e=>{
    console.log('拖拽开始了!');
});

🚀 返回目录

注意事项

手势识别器的name字段必填

自定义手势一定记得给起一个名字哦, 而且不要和默认存在的手势同名(已有tap/swipe/pan/rotate/pinch/press).

at.use(Tap, { pointLength: 2 , name:'twoFingersTap'});
at.on('twoFingersTap', onTwoFingersTap);

不要用 alert 调试

❗️❗️❗️ 在安卓手机的真机上, 如果touchstarttouchmove阶段触发了alert, 会出现后续的touchmove/touchend不触发的 bug. 所以请大家务必避免在手势的事件回调中使用alert. 测试代码

如果仅仅是了在移动端调试, 请使用腾讯的vconsole

macos上的chrome浏览器触发touchend会比较慢

由于上述原因, swipe事件发生的会"慢半拍",所以请大家最终测试以手机效果为准.

移动端尽量使用tap代理click

在移动端touchstart比click先触发, 所以touchstart阶段的preventDefault会阻止click触发, 恰恰any-touch默认在touchstart中使用了preventDefault, 用来阻止了浏览器默认事件的触发,比如click和页面滚动.

如果移动端非要使用click做如下设置

const at = new AnyTouch(el, { preventDefault: false });

🚀 返回目录

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].