微信小顺序 克己手势库

WxTouchEvent 微信小顺序手势事宜库

因为微信小顺序只能够支撑 tap,longtap,touchstart,touchmove,touchcancel,touchend时刻,关于比较复杂的事宜只能本身完成
因而本身对 alloyFinger库举行了革新,开发了时刻微信小顺序手势事宜库WxTouchEvent,运用 ES
6举行编写,手势库支撑以下事宜

  • touchStart

  • touchMove

  • touchEnd

  • touchCancel

  • multipointStart

  • multipointEnd

  • tap

  • doubleTap

  • longTap

  • singleTap

  • rotate

  • pinch

  • pressMove

  • swipe

git堆栈地点:点我点我

运用

因为和微信小顺序强绑定,因而须要在元素上面绑定好一切的事宜,誊写比较贫苦,因而发起关于原生支撑的运用原生去处理,
只有当须要 pinch,rotate,swipe 等特别事宜才运用这个事宜库完成

装置 npm i wx-touch-event --save , 或许直接从 git 库 checkout 出来

绑定要领

*.wxml

wxml中对须要监听时刻的元素绑定 touchstart、touchmove、touchend、touchcancel四个事宜
页面誊写成

    <view class="info-list" 
          bindtouchstart="touchStart"
          bindtouchmove="touchMove"
          bindtouchend="touchEnd"
          bindtouchcancel="touchCancel"
        >
        
    </view>

*.js

js逻辑层须要实例化WxTouchEvent, 实例中有start、move、end、cancel对应\*.wxml绑定的bindtouchstart,bindtouchmove,bindtouchend,bindtouchcancel,须要将事宜的回调函数一一对应,
誊写成:

import WxTouchEvent from "wx-touch-event";

let infoListTouchEvent = new WxTouchEvent();//在 Page外实例化函数,能够直接复制给 Page 中的回调函数
Page({
    onLoad: function() {
        this.infoListTouchEvent = infoListTouchEvent;
        this.infoListTouchEvent.bind({//初始化后绑定事宜
            swipe: function(e) {
                console.log(e);
            },
            doubleTap: function(e) {
                console.log(e);
            },
            tap: function(e) {
                console.log(e);
            }.bind(this),
            longTap: function(e) {
                console.log(e);
            },
            rotate: function(e) {
                console.log(e)
            }.bind(this),
            pinch: function(e) {
                console.log(e);
            }

        })
    },
    touchStart: infoListTouchEvent.start.bind(infoListTouchEvent),
    touchMove: infoListTouchEvent.move.bind(infoListTouchEvent),
    touchEnd: infoListTouchEvent.end.bind(infoListTouchEvent),
    touchCancel: infoListTouchEvent.cancel.bind(infoListTouchEvent),

});
    原文作者:斑驳光影
    原文地址: https://segmentfault.com/a/1190000009252743
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞