V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
makelove
V2EX  ›  JavaScript

2022 年哪个手势识别库最好用?

  •  
  •   makelove · 2022-01-12 09:01:42 +08:00 · 2741 次点击
    这是一个创建于 806 天前的主题,其中的信息可能已经有所发展或是发生改变。

    搜索了下貌似很多都不更新了?

    我要做个图片查看器,可以类似手机里的系统图片查看器可以双指放大的那种,貌似一个这种好用的图片查看器 js 组件都没有?说好的前端轮子多呢。我只好自己来了。

    最好是有 typescript ,没有的话代码要简单我可以自己改。

    9 条回复    2022-01-13 09:46:46 +08:00
    Ritr
        1
    Ritr  
       2022-01-12 09:50:05 +08:00   ❤️ 1
    hammer.js
    66beta
        2
    66beta  
       2022-01-12 09:55:57 +08:00
    hammer.js 应该可以再用 100 年
    oott123
        3
    oott123  
       2022-01-12 11:19:56 +08:00
    针对你的原始需求,https://photoswipe.com 好像比较出名。
    makelove
        4
    makelove  
    OP
       2022-01-12 12:17:34 +08:00
    @oott123 这个我之前搜到过测试了下它的 demo 没几秒就发现有 bug 就直接 pass 了(就是双指缩放时图片会跳,比如突然跳到左上角了或跳没了,bug 出现频率非常高
    h82258652
        5
    h82258652  
       2022-01-12 12:33:31 +08:00
    hammer.js+1 ,n 年前 jQuery 时代就用它了,现在还是用它
    makelove
        6
    makelove  
    OP
       2022-01-12 12:41:14 +08:00
    hammer 有点老,且似乎也不更新了,体积又大。

    搜索到有一些国产的
    https://any86.github.io/any-touch/
    https://github.com/18223781723/noname-gesture/
    http://alloyteam.github.io/AlloyFinger/

    发现基本的手势识别也很简单啊,最后一个核心代码只有 100 行,打算基于最后一个搞自己的轮子用 ts 重写。demo 上功能少了运动速度(就是手一松就停了)和双指放大不是从中心放大的,不过既然是做轮子了这些也能加上。
    tanranran
        7
    tanranran  
       2022-01-12 12:51:40 +08:00
    AlloyFinger +1 基于 AlloyFinger 魔改过
    makelove
        8
    makelove  
    OP
       2022-01-12 22:28:31 +08:00
    @tanranran 搞了才发现从 AlloyFinger 开始不合适,这货是基于 touch events 事件,没法用于鼠标操作,因为和 pointer events 差别巨大还不好改,我还是从 noname-gesture 开始吧
    noobma
        9
    noobma  
       2022-01-13 09:46:46 +08:00
    https://github.com/xd-tayde/mtouch

    demo 里面有拖动、双指放大、旋转
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1539 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 17:11 · PVG 01:11 · LAX 10:11 · JFK 13:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.