1

I'm using the ionic2 to programing a mobile app.I want to record the whole trail when the finger touch and move on the screeen.first,I used the

 document.addEventListener('touchmove',touch,false);
but when the finger touch and move on the screen,the app only fire the touchmove event one time, I can only get a point, not a series of touched points,how can I do?
pies
  • 61
  • 1
  • 1
  • 5

1 Answers1

1

You can setup event bindings for touchstart and touchmove. These event bindings will call the method when screen will be touched or dragged and return trail of coordinates.

home.html

<ion-content padding>
  <div 
    id="my-div"
    (touchstart)="handlestart($event)"
    (touchmove)="handlemove($event)">
  </div>
</ion-content>

home.ts

export class HomePage {
  handlestart(event) {
    console.log('start: X:' + event.touches[0].pageX + ', Y:' +event.touches[0].pageY);
  }

  handlemove(event) {
    console.log('move: X:' + event.touches[0].pageX + ', Y:' +event.touches[0].pageY);
  }
}

Output

enter image description here

Tony Stark
  • 265
  • 2
  • 16