TouchSwipe所有活动

时间:2015-04-01 10:30:29

标签: javascript jquery touch touchswipe

我正在尝试处理我的函数中的事件。所以它在我的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'
    });
});

1 个答案:

答案 0 :(得分:0)

您可以获取滑动方向(但不是缩放方向),这样可以减少很多代码(见下文)。

关于点按,您不得在内部设置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'
    });
});