No scrolling on the mobile side

Source: Internet
Author: User

varstartpos = 0,endpos = 0,isscrolling = 0;d Ocument.addeventlistener (' Touchstart ',function(event) {vartouch = event.targettouches[0];//touches array objects get all the touch on the screen, take the first touchstartpos = {x:touch.pagex,y:touch.pagey,time:+NewDate};//take the coordinate value of the first touchisscrolling = 0;//This parameter determines whether to scroll vertically or horizontally},false);//Unbind Event web front-end developmentDocument.addeventlistener (' Touchend ',function(event) {Document.removeeventlistener (' Touchmove ', This,false);d Ocument.removeeventlistener (' Touchend ', This,false);}, false);d Ocument.addeventlistener (' Touchmove ',function(event) {//do not perform a move operation when the screen has multiple touch or the page is being retractedif(Event.targetTouches.length > 1 | | event.scale && event.scale!== 1)return;varTouch = Event.targettouches[0];endpos= {X:touch.pagex-startpos.x,y:touch.pagey-Startpos.y};//alert (Math.Abs (endpos.x) + "----" +math.abs (ENDPOS.Y));isscrolling = Math.Abs (endpos.x) < Math.Abs (ENDPOS.Y)? 1:0;//isscrolling is 1 o'clock, indicates longitudinal slide, 0 is transverse slideif(isscrolling = = 0){//Event.preventdefault ();//blocking the default behavior of touch events, which is to prevent scrolling}if(Math.Abs (endpos.x) > 5) {event.preventdefault ();//Horizontal slide Ban}}, false);//Prevent page scrolling//document.body.addEventListener (' Touchmove ', function (event) {//Event.preventdefault ();//}, True);

No scrolling on the mobile side

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.