Angular/ionic Custom Click

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.