JS to achieve the mobile end of the finger left and right swipe page effect

Source: Internet
Author: User

varEle = Document.getelementsbyclassname ("Img-box") [0]; varBeginX, BeginY, EndX, EndY, Swipeleft, swiperight; Ele.addeventlistener (' Touchstart ',function(event) {event.stoppropagation ();            Event.preventdefault (); BeginX= Event.targettouches[0].screenx; BeginY= Event.targettouches[0].screeny; Swipeleft=false, swiperight =false;        }); Ele.addeventlistener (' Touchmove ',function(event) {event.stoppropagation ();            Event.preventdefault (); EndX= Event.targettouches[0].screenx; EndY= Event.targettouches[0].screeny; //Swipe left and right            if(Math.Abs (Endx-beginx)-Math.Abs (Endy-beginy) > 0) {                /*Swipe Right*/                if(Endx-beginx > 0) {swiperight=true; Swipeleft=false; }                /*Swipe left*/                Else{swipeleft=true; Swiperight=false; }            }            Else if(Math.Abs (Endx-beginx)-Math.Abs (Endy-beginy) < 0)            {                //swipe up and down            }        }); Ele.addeventlistener (' Touchend ',function(event) {event.stoppropagation ();            Event.preventdefault (); if(Math.Abs (Endx-beginx)-Math.Abs (Endy-beginy) > 0) {event.stoppropagation (); Event.preventdefault ();if(swiperight) {swiperight= !swiperight; / * swipe right *    /                }                if(swipeleft) {swipeleft= !swipeleft; / * swipe left *    /                }            }        });

In addition to this approach you can use third-party plug-ins to achieve the same effect, such as QUOJS contains a variety of mobile gesture effects and AJAX requests and other operations, but in the use of the process encountered problems. After using Quojs, some of the jquery's click events and some of the A-tag href properties are invalidated. and found Quojs in the Swipeleft and swiperight events, the finger can only slide horizontally, if a little tilt a little sliding, then the event does not take effect, do not know whether it is my device problem.

JS to achieve the mobile end of the finger left and right swipe page effect

Related Article

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.