Projects are used on PC Web pages and on mobile devices such as ipads.
When a user's finger taps a button on a large screen device on the ipad, a slight shift may occur that prevents the Click event from being triggered.
will give the user a less sensitive feeling, in order to solve this problem I write a command instead of click.
Paste the code:
@Directive ({selector: ' [Yun-click] '}) Export class Yunclickdirective implements OnInit, OnDestroy {@Output (' yun-cli CK ') Eventclick = new Eventemitter (); Unsubscribe: () = void; Constructor (private platform:platform, private renderer:renderer2, private element:elemen TREF) {} ngoninit () {if (This.platform.is (' mobile ') | | this.platform.is (' mobileweb ') | | this.platform.is (' p Hablet ') | | This.platform.is (' tablet ')) {This.yuntouch (); } else {This.yunclick (); }}//Touch event, moving end and sliding distance less than 30px trigger Yuntouch () {Let StartX, Starty, EndX, EndY; Monitor Touchstart This.unsubscribe = This.renderer.listen (this.element.nativeElement, ' Touchstart ', (even T:touchevent) + (Let touch = event.targettouches[0]; StartX = Touch.pagex; Starty = Touch.pagey; Console.log (StartX, starty); }); Monitoring TOUChmove this.unsubscribe = This.renderer.listen (this.element.nativeElement, ' Touchmove ', (Event:touchev ENT) = {Let touch = event.targettouches[0]; EndX = Touch.pagex; EndY = Touch.pagey; Console.log (EndX, EndY); }); Monitor Touchend This.unsubscribe = This.renderer.listen (this.element.nativeElement, ' touchend ', (event:t ouchevent) = = {Let Distancex = Math.Abs (endx-startx), Distancey = Math.Abs (Endy-starty); Console.log (Distancex, Distancey); Let distance = Math.sqrt ((Math.pow (Distancex, 2) + Math.pow (Distancey, 2)); Calculating the sliding distance console.log (distance); if (Distance < | |!endx | |!endy) {//No sliding, no trigger touchmove, need to determine this.eventClick.emit (event); } }); }//Click event Yunclick () {this.unsubscribe = this.renderer.listen (thIs.element.nativeElement, ' click ', event = {Console.log (event); This.eventClick.emit (event); }); } Ngondestroy () {this.unsubscribe (); } }
Use the same as click and change the click to Yun-click. Oh, don't forget to add it to the module.
Angular/ionic Custom Click