jquery notation:
$ (' #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;}
Native notation:
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)})
Touchend need to use changedtouches[0 in both of these approaches]
Generally we take the coordinates of the first finger, if there are other requirements may need to determine the number of fingers
if (E.targettouches.length = = 1) { //...}
By the way, put a common sentence
E.preventdefault ();
JQuery get touchstart,touchmove,touchend coordinates