如果事件类型等于touchstart

时间:2016-11-28 08:28:37

标签: jquery touch mouseevent

我可以检查mousedown是否已被触发:

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

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

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

这确实起了作用。有人可以就如何实现这个目标提供指导吗?

1 个答案:

答案 0 :(得分:1)

检查if属性的e.type语句是正确的逻辑。但是你的情况失败了,因为你挂钩mousemovetouchmove,而不是touchstart

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

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

检查type的{​​{1}}属性,如果这是您的意图:

touchmove