触摸滑动所有事件

TouchSwipe all events

本文关键字:事件 触摸      更新时间:2023-09-26

我正在尝试处理函数中的事件。所以它在我的gameLogic函数中为每种类型的事件做了一些事情。

虽然,TAP没有得到认可。。。

我该怎么办?我应该把每个活动分开吗?

$(function() {  
    $(".main-wrapper-inner").swipe( {
        //Generic swipe handler for all directions  
        tap:function(event, target) {
            gameLogic("tap");
        },
        swipeLeft:function(event, distance, duration, fingerCount, fingerData) {
          gameLogic("swipeLeft");
        },
        swipeRight:function(event, distance, duration, fingerCount, fingerData) {
          gameLogic("swipeRight");
        },
        swipeUp:function(event, distance, duration, fingerCount, fingerData) {
          gameLogic("swipeUp");
        },
        swipeDown:function(event, distance, duration, fingerCount, fingerData) {
          gameLogic("swipeDown");
        },
        pinchIn:function(event, direction, distance, duration, fingerCount, pinchZoom, fingerData) {
          gameLogic("pinchIn");
        },
        pinchOut:function(event, direction, distance, duration, fingerCount, pinchZoom, fingerData) {
             gameLogic("pinchOut");
        },
       threshold:0,
       fingers: 'all'
    });
});

您可以获得滑动方向(但不能获得夹取方向),因此可以减少大量代码(见下文)。

关于点击,您不能将threshold: 0设置为内部禁用所有点击/点击事件。将threshold设置为高于0的任何值,或完全忽略它(默认为75),以使抽头功能在中工作

$(function() {  
    $(".main-wrapper-inner").swipe( {
        //Generic swipe handler for all directions  
        tap:function(event, target) {
            gameLogic("tap");
        },
        swipe(event, direction) {
          // You can obtain the swipe direction
          // and process it in your game logic
          gameLogic("swipe", direction);
        }
        pinchIn:function(event) {
          gameLogic("pinchIn");
        },
        pinchOut:function(event) {
          gameLogic("pinchOut");
        },
        threshold: 75, // This must NOT be 0 for taps to work
        fingers: 'all'
    });
});