2012-11-01 41 views
0

当用户在页面元素上向左滑动并在滑动发生时运行某个函数时,是否可以捕获?我有一些解决方案,但是如果你在页面上向下滚动,并且你的手指在元素上稍微向左滑动,它会运行该函数。刷卡时向左轻扫?

我目前的解决方案:

function touchMove() { 
    finalCoord.x = event.targetTouches[0].pageX; 
    changeX = originalCoord.x - finalCoord.x; 
    var changeY = originalCoord.y - finalCoord.y; 
    if (changeY < threshold.y && changeY > (threshold.y * -1)) { 
     changeX = originalCoord.x - finalCoord.x; 
     if (changeX > threshold.x) { 
      $(document).off("touchmove", ".row"); 
      if ($(event.target).attr("class") === "row-inside") { 
       var element = $(event.target); 
      } 
      if ($(event.target).attr("class") === "row-l") { 
       var element = $(event.target).parent(); 
      } 
      if ($(event.target).attr("class") === "row-r") { 
       var element = $(event.target).parent(); 
      } 
      setTimeout(function() { 
       $(document).on("touchmove", ".row", function() { 
        touchMove(); 
       }); 
      }, 800); 
     } 
    } 
} 
function touchStart() { 
    originalCoord.x = event.targetTouches[0].pageX; 
    finalCoord.x = originalCoord.x; 
} 
$(document).on("touchmove", ".row", function() { 
    touchMove(); 
}); 
$(document).on("touchstart", ".row", function() { 
    touchStart(); 
}); 
} 

我想过使用jQuery移动,但swipeLeft事件仅触发时挥动结束,而不是在。

回答