如果事件类型等于TouchStart



我可以检查 mousedown是否像这样触发:

$(something).on("mousemove touchmove", function(e) {
    if (e.buttons == 1){
        // mouse is down
    }
})

非常简单的问题,如何检查上面的touchstart是否已触发?我尝试了:

if (e.type === 'touchstart'){
    // touchstart has been triggered
}

这确实起作用了。有人可以提供有关如何实现这一目标的方向吗?

您的if语句检查e.type属性是正确使用的逻辑。不过,您的病情失败了,因为您可以钩到mousemovetouchmove,而不是touchstart

您需要在事件列表中包含touchstart

$(something).on("mousemove touchmove touchstart", fn);

检查typetouchmove属性,如果是您的意图:

if (e.type === 'touchmove'){
    // touchmove has been triggered
}

最新更新