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