Skip to content

Instantly share code, notes, and snippets.

@Katheesh
Created January 27, 2023 06:15
Show Gist options
  • Save Katheesh/6e459e9fdd7f7173f017d3c892e272c5 to your computer and use it in GitHub Desktop.
Save Katheesh/6e459e9fdd7f7173f017d3c892e272c5 to your computer and use it in GitHub Desktop.
Mesure swipe action using angular type script
import { Component, HostListener, Input, OnInit } from '@angular/core';
export class AppbarComponent implements OnInit {
touchstartX:number = 0;
touchstartY:number = 0;
touchendX:number = 0;
touchendY:number = 0;
@HostListener('touchstart', ['$event']) gesuredZonestart(event:any) {
this.touchstartX = event.changedTouches[0].screenX;
this.touchstartY = event.changedTouches[0].screenY;
}
@HostListener('touchend', ['$event']) gesuredZoneend(event:any) {
this.touchendX = event.changedTouches[0].screenX;
this.touchendY = event.changedTouches[0].screenY;
this.handleGesure();
}
handleGesure() {
var swiped = 'swiped: ';
if (this.touchendX < this.touchstartX) {
console.log(swiped + 'left!');
}
if (this.touchendX > this.touchstartX) {
console.log(swiped + 'right!');
}
if (this.touchendY < this.touchstartY) {
console.log(swiped + 'down!');
}
if (this.touchendY > this.touchstartY) {
console.log(swiped + 'top!');
}
if (this.touchendY == this.touchstartY) {
console.log('tap!');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment