如果事件类型等于 touchstart
if event type is equal to 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
属性 的语句是正确的使用逻辑。但是你的条件失败了,因为你挂钩到 mousemove
和 touchmove
,而不是 touchstart
.
您需要在事件列表中包含 touchstart
:
$(something).on("mousemove touchmove touchstart", fn);
或 检查 type
属性 是否为 touchmove
,如果这是你的意图:
if (e.type === 'touchmove'){
// touchmove has been triggered
}
我可以检查 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
}