Javascript 在刷卡时捕获向左刷卡?

Javascript 在刷卡时捕获向左刷卡?,javascript,jquery,Javascript,Jquery,是否可以捕获用户在页面元素上向左滑动的时间,然后在滑动过程中运行函数?我有一个解决方案,但是如果你在页面上向下滚动,你的手指稍微向左滑动一个元素,它就会运行这个函数 我当前的解决方案: function touchMove() { finalCoord.x = event.targetTouches[0].pageX; changeX = originalCoord.x - finalCoord.x; var changeY = originalCoord.y - fin

是否可以捕获用户在页面元素上向左滑动的时间,然后在滑动过程中运行函数?我有一个解决方案,但是如果你在页面上向下滚动,你的手指稍微向左滑动一个元素,它就会运行这个函数

我当前的解决方案:

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();
});
}
函数touchMove(){
finalcord.x=event.targetTouches[0].pageX;
changeX=originalcord.x-finalcord.x;
var changeY=原始订单y-最终订单y;
if(changeY(threshold.y*-1)){
changeX=originalcord.x-finalcord.x;
如果(changeX>threshold.x){
$(document).off(“touchmove”,“.row”);
if($(event.target).attr(“类”)=“行内”){
var元素=$(event.target);
}
if($(event.target).attr(“类”)=“行-l”){
var元素=$(event.target).parent();
}
if($(event.target).attr(“类”)=“行-r”){
var元素=$(event.target).parent();
}
setTimeout(函数(){
$(document).on(“touchmove”,.row”,函数(){
touchMove();
});
}, 800);
}
}
}
函数touchStart(){
originalcord.x=event.targetTouches[0].pageX;
FINALCORD.x=原始ORD.x;
}
$(document).on(“touchmove”,.row”,函数(){
touchMove();
});
$(document).on(“touchstart”,“.row”,函数(){
touchStart();
});
}

我曾考虑过使用jQuery mobile,但swipeLeft事件只在刷卡结束时触发,而不是在刷卡过程中触发。

这个术语是拖动

我尝试了很多方法,到目前为止最好的方法是使用Hammer.js

使用Hammer.js dragleft事件

在您的移动设备上查看一些示例:对于dragleft,请尝试旋转木马