我可以检查 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
属性是正确使用的逻辑。不过,您的病情失败了,因为您可以钩到mousemove
和touchmove
,而不是touchstart
。
您需要在事件列表中包含touchstart
:
$(something).on("mousemove touchmove touchstart", fn);
或检查type
的touchmove
属性,如果是您的意图:
if (e.type === 'touchmove'){
// touchmove has been triggered
}