學習記錄:touch事件的座標獲取

touch 事件獲取座標javascript

jq:java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$( '#id' ).on( 'touchstart' , function (e) {
   var  _touch = e.originalEvent.targetTouches[0];
   var  _x= _touch.pageX;
});
 
$( '#id' ).on( 'touchmove' , function (e) {
   var  _touch = e.originalEvent.targetTouches[0];
   var  _x= _touch.pageX;
});
 
$( '#id' ).on( 'touchend' , function (e) {
   var  _touch = e.originalEvent.changedTouches[0];
   var  _x= _touch.pageX;
}

 

js:spa

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
document.getElementById( "id" ).addEventListener( "touchstart" , function (e){
     var  _x=e.touches[0].pageX;
     var  _y=e.touches[0].pageY;
     console.log( "start" ,_x);
});
document.getElementById( "id" ).addEventListener( "touchmove" , function (e){
     var  _x=e.touches[0].pageX;
     var  _y=e.touches[0].pageY;
     console.log( "move" ,_x);
});
document.getElementById( "id" ).addEventListener( "touchend" , function (e){
     var  _x=e.changedTouches[0].pageX;
     var  _y=e.changedTouches[0].pageY;
     console.log( "end" ,_x);
});

 

相關解釋:code

targetTouches 表示的是手指列表 
changedTouches 表示的是手指事件 ,在 touchend 裏就是手指離開blog

相關文章
相關標籤/搜索