Mobile development Fastclick Click through

Source: Internet
Author: User

Penetration (Dianchuan) is a common bug that occurs in various browsers on mobile. May be caused by a delay of the Click event (300ms) or event bubbling

Phenomenon: There is a btn1< or a tag in page A, and on page b there is a btn2,btn1 and btn1 in the same position on the screen, two buttons have their own click events. The BTN1 click event triggers and jumps to page B. When BTN1 is clicked and jumps to page B, the Click event of the Btn2 button is also triggered.

The general solution is as follows:

A. Using Fastclick, this can be a perfect solution to the Dianchuan problem.

B. Add preventdefault to the Touchend event callback and add Pointer-events:none to the next layer.

However, the page a tag still exists click through , causing the page to jump, Fastclick no effect

After online search and practice, summarize the following scenarios

1. Use Touchstart,touchmove,touchend to simulate a click event so that, in addition to preventing penetration, the event will respond more quickly.

The click of the mobile side is the touch before the trigger is simulated and the order of triggering is:

touchstart-> touchmove-> touchend-> mousedown-> mousemove-> mouseenter-> Click

2. There is 300ms delay on the mobile side, then put a mask layer in page b <div id= "Dcmask" > </div>, cover all the contents of the page, and wait for the B page to finish loading, hide the mask layer

<id= "Dcmask"> </div>
$ (function() { 
SetTimeout (function() {$ (' #dcMask '). Hide (); },300);
});

3. Using the CSS Pointer-events:none

First use pointer-events to disable the element of the Click event, the page loaded after 300ms recovery event, set Pointer-events:auto

A[href] { pointer-events:none;
}
$ (function() {setTimeout (function() {$ (' a[href] '). css (' pointer-events ', '  Auto '); });

Mobile development Fastclick Click through

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.