Completely solve the low-end Android phone Touchend event does not trigger (consider scroll)

Source: Internet
Author: User

This mobile development encountered the Android 4.2 system can not trigger touchend problems, there are the following requirements.

1. Horizontal Pulley Map

2. Drop-down Refresh page content

3.body scroll bar cannot be invalidated

The Touchend event can be triggered when the browser default behavior is blocked at the beginning of the Carousel Diagram Touchmove event.

Drag-and-drop carousel diagram
Parentnode.addeventlistener (' Touchmove ', function (e) { e.preventdefault ();

Then copied a copy of the drop-down refresh event (at which point the drop-down refresh is OK)

Drop-down Refresh code  document.addeventlistener (' Touchmove ', function (e) {        if (gettopdistance () <=) {                E.preventdefault ();        }    });

However, the new problem came out again, the page can not scroll up and down, after analysis of the Touchmove event in the document to prevent the browser default behavior causes the page can not swipe up and down.

Finally referred to a foreigner's article to solve this problem. (Horizontal slip fried over 7 think it is a drag-and-drop recording map)

     Parentnode.addeventlistener (' Touchmove ', function (e) {                var _x = E.touches[0].pagex;                if ((Math.Abs (_X-PARENTNODE.STARTX) >7)) {                    e.preventdefault ();                }                E.stoppropagation ();            

The drop-down refresh also adds a judging condition that determines whether the browser default behavior is blocked (scrolling more than 10 vertically prevents browser default behavior)

Document.addeventlistener (' Touchmove ', function (e) {              if (gettopdistance () <= 10) {//when scroll bar position is less than            //alert (' < ');            var _x = E.touches[0].pagex;            var _y = E.touches[0].pagey;            if (_y-obj.y > 10) {//scroll distance greater than                e.preventdefault ();}}    );

/* Get scroll bar position
*/
function Gettopdistance () {
return Document.documentElement.scrollTop | | Window.pageyoffset | | Document.body.scrollTop;
}

Completely solve the low-end Android phone Touchend event does not trigger (consider scroll)

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.