Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic get Drag Coordinates

I'm new to working with Ionic and would like to get the current coordinates of the touch(or mouse) while pressed(update every 100ms or smth). So the coordinates where the mouse is while pressed. I've tried it with the Ionic Pan gesture but couldn't get it to work.

Any help appreciated!

like image 267
Barcoma Avatar asked Aug 26 '26 14:08

Barcoma


1 Answers

You can use a simple ion-content element and capture the click event in your comp

<ion-content (click)="getCoordinates($event)">
 This is my main content
</ion-content>

Then in your component code just use event.clientX like this:

getCoordinates(ev) { 
  console.log('x: ' + ev.clientX + ' y: ' + ev.clientY);
}
like image 162
AntonioGarcía Avatar answered Aug 29 '26 04:08

AntonioGarcía



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!