为什么是event.offsetX"当"touchstart"事件

Why is "event.offsetX" undefined when "touchstart" event?

本文关键字:quot touchstart 事件 为什么 event offsetX      更新时间:2023-09-26

我试图捕获touchstart相对于元素(".canvas")的位置是否有可能捕获此事件offsetXoffsetY ?

$(".canvas").on("mousemove", function(event){
     console.log(event.offsetX + " - " + event.offsetY);
})

click事件:http://jsfiddle.net/jfejc6zw/1/

使用touchstart事件(用你的手机或模拟器测试)http://jsfiddle.net/jfejc6zw/2/

提前感谢!

如果你已经在使用jQuery了,为什么还要使用低级事件坐标呢?只要使用jQuery的。offset()和。position()函数,就知道jQuery已经解决了所有的浏览器不一致问题。