Hack mode of touch event invalidation for Android part model

Source: Internet
Author: User

General write a slide code that we might write

Initevent:function () {This.el.addEventListener ("Touchstart", This.touchStart.bind (this));            This.el.addEventListener ("Touchmove", This.touchMove.bind (this));        This.el.addEventListener ("Touchend", This.touchEnd.bind (this));            }, Touchstart:function (e) {var touches = e.touches[0]; This.startstatus = {X:touches.pagex, Time:Date.now ()} THIS.VALIDSL        IDE = FALSE;            }, Touchmove:function (e) {var touches = e.touches[0];            E.preventdefault ();                 This.endstatus = {X:touches.pagex, Time:Date.now ()} This.delta = {             X:this.endstatus.x-this.startstatus.x, Time:this.endstatus.time-this.startstatus.time            } this.translate (this.delta.x + ' px ', 0);        This.validslide = true;      }, Touchend:function (e) {      if (this.validslide) {var deltax = Math.Abs (this.delta.x), dir = this.delta.x/d                        Eltax, con = (DeltaX > WINDOW.INNERWIDTH/3 | | this.delta.time < + && DeltaX > 20) && ((this.delta.x > 0 && this.el.querySelector ('. Prev ')) | |                (this.delta.x < 0 && this.el.querySelector ('. Next ')));                    if (con) {this.translate (dir * window.innerwidth + ' px ', this.speed);                    SetTimeout (function () {Window.s.trigger (' slide ', [dir]);                }, This.speed);                } else {this.translate (' 0px ', this.speed); }            }        },

To copy and paste directly, please ignore the relevant business code. Generally, add E.preventdefault () in Touchmove to prevent the Android phone from triggering only one move and not triggering the end event.

But this will still be in the Android part of the model, such as Samsung mobile phone does not trigger the touch event problem, the specific hack method is to bind the document also a Touchmove event to prevent the browser default action

    

  

Hack mode of touch event invalidation for Android part model

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.