Created
November 29, 2019 04:49
-
-
Save kawinpop/e5bf1eab3cada7e4a38eab709fb941ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, HostListener, Output, EventEmitter, Input } from '@angular/core'; | |
@Directive({ | |
selector: '[ng-touch]' | |
}) | |
export class TouchDirective { | |
@Output() | |
touch = new EventEmitter(); | |
@Input() | |
timemove: number; | |
countTouchMove = 0; | |
@HostListener('click', ['$event']) onclick($event) { | |
if (event.cancelable) { | |
event.preventDefault(); | |
} | |
} | |
@HostListener('touchstart', ['$event']) ontouchstart($event) { | |
if (this.timemove === 0) { | |
this.touch.emit(); | |
} | |
} | |
@HostListener('touchmove', ['$event']) ontouchmove($event) { | |
this.countTouchMove++; | |
} | |
@HostListener('touchend', ['$event']) ontouchend($event) { | |
if (event.cancelable) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
} | |
const time = this.timemove || 3; | |
if (this.countTouchMove < time) { | |
this.touch.emit(); | |
} | |
this.countTouchMove = 0; | |
} | |
constructor( | |
) { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment