JS Mobile-tap Event encapsulation

Source: Internet
Author: User

These days to do the project, found that mobile needs to touch the event, and click must not be, so I have the Tap event encapsulation Search, found an article, the original address is as follows: Http://www.jb51.net/article/50663.htm,

I add something to the first package, wrap it in a function, call it directly when you use it, and the source code is as follows (Tap.js):

function tap (Ele, fn) {    var starttx, Startty;    var endtx, Endty;    Ele.addeventlistener (' Touchstart ', function (e) {    var touches = e.touches[0];    Starttx = Touches.clientx;    Startty = Touches.clienty;}, False); Ele.addeventlistener (' Touchend ', function (e) {    var touches = e.changedtouches[ 0],    endtx = Touches.clientx,    endty = Touches.clienty;    if (Math.Abs (STARTTX-ENDTX) < 6 && Math.Abs (STARTTY-ENDTY) < 6) {        fn ();    }}, False);}

Using the method, introduce the JS file (i.e. tap.js) and execute the following call:

/*    parameter Description:    ele: Native DOM object    fn: Callback method, perform the action you need    */tap (Ele,function () {    //action you need to perform});    

  

JS Mobile-tap Event encapsulation

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.