JQuery获取touchstart,touchmove,touchend坐标

$('#id').on('touchstart',function(e) {
    var x= e.originalEvent.targetTouches[0].pageX;
    
});

JQuery如上。html

 

document.getElementById("id").addEventListener("touchstart",function(e){
    var _x=e.touches[0].pageX;
    var _y=e.touches[0].pageY;
    console.log("start",_x)
})

原生如上。spa

 

通常咱们取第一个手指的坐标,若是有其余要求可能 须要判断手指数量code

 

if (e.targetTouches.length == 1){
  //...
}

 

经常使用的:htm

e.preventDefault();

 

参考来源:http://www.cnblogs.com/luoeeyang/p/4519408.htmlblog

相关文章
相关标签/搜索