Click through principle and solve

Source: Internet
Author: User

First, the event triggering sequence

  most of the actions on the PC Web page are mouse-responses, which are mouse events, including mousedown , mouseup , mousemove and the click event. One-click behavior can be disassembled into: mousedown mouseup  click - ---three steps.

There is no mouse on the phone, so use touch events to achieve similar functions. The touch event contains touchstart ,, touchmove touchend , notice that there are no events on the phone tap . The process by which a finger triggers a touch event is:--- touchstart touchmove touchend .

There is no mouse on the phone, but it does not mean that the phone cannot respond to the mouse event (actually using touch to trigger the mouse event). This means that the click event on the mobile side can be disassembled as: touchstart touchmovetouchend -> click。

The browser waits approximately 300ms after touchend, and if there is no tap behavior, the Click event is triggered. The reason the browser waits about 300ms is to determine if the user is double-clicking (double tap), which is not appropriate to trigger the Click event during a double-click. From this you can see that the Click event Trigger represents the end of a round of touch events.

As mentioned above, there is no tap event in the native event, so you can refer to the classic zepto.js handling of the Singletap event. See Source 136-143 Line

It can be seen that the triggering time of the Singletap event-the SINGLETAP is triggered after the Touchend event response 250ms has no action.

  

Second, click through the scene and why

With the above foundation, we can understand why the click-through phenomenon occurs. We often see the "pop-up/float" stuff, and I have a demo.

The entire container has an underlying element div, and a popup layer div, in order for the popup layer to have a modal box effect, I added a mask layer.

<div class= "Container" >    <div id= "Underlayer" > underlying elements </div>    <div id= "Popuplayer" >        <div class= "layer-title" > Popup layer </div>        <div class= "layer-action" >            <button class= " BTN "id=" Closepopup "> Close </button>        </div>    </div></div><div id=" Bgmask "> </div>

The Click event is then bound for the underlying element, and the Close button of the popup layer binds the tap event.

function (e) {    $ (' #popupLayer '). Hide ();    $ (' #bgMask '). Hide ();}); $ (function() {    alert (' Underlayer clicked ');});

Click the Close button, Touchend first trigger tap, the pop-up layer and mask are hidden. After Touchend continues to wait for 300ms to find no other behavior, continue to trigger click, because the popup layer has disappeared, so the current click event Target is on the underlying element, so the alert content. The entire event trigger process is Touchend, tap-click.

And because the Click event hysteresis (300ms), in which the upper element of the 300ms is hidden or disappeared, the lower layer of the same DOM element triggers the Click event (if the input box will trigger the focus event), it looks like the click of the target "penetrate" to the lower level.

  Therefore, clicking through the phenomenon is easy to understand, within this 300ms, because the upper element is hidden or disappeared, because of the click event hysteresis, the same location of the DOM element triggered the Click event (if input triggered the focus event). In the code, the feeling is that target has drifted.

Third, the settlement

1. when the Touchend event is triggered at the end of the touch, Preventdefault (). It doesn't seem to be a problem, but unfortunately not all browsers support it.

2. Prohibit page scaling by setting meta tags, you can disable page scaling, some browsers no longer need to wait for 300ms, resulting in click through. Click events are still triggered, but relatively fast, so the click event can in some sense replace the Click event, at the expense of a few users (the Click event triggers the still slower) experience.

<meta name= "viewport" content= "Width=device-width, User-scalable=no" >
IE 10 can use CSS to cancel the click-through delay:
HTML {    -ms-touch-action:manipulation;    Touch-action:manipulation;}

IE 11+ can use touch-action: manipulation; attributes to block the double-click scaling of an element.

3. Although the CSS3 approach is primarily about events, it is necessary to introduce a CSS3 attribute--pointer-events.

Pointer-events:  Auto | none | visiblepainted | visiblefill | visiblestroke | visible | painted | fill | stroke | all | Inherit

The Pointer-events property has a number of values that are useful primarily for auto and none, and other properties for the SVG service.

View browser support Visibility Mobile development is still available.

Properties meaning
Auto Default value, mouse or touch screen event does not penetrate the current layer
None The element is no longer target, and the listening element becomes the underlying element (such as the fruit element is set to auto, and clicking on the child element will continue to listen for events)

  4. The extended vanishing event can take advantage of jquery's fadeout, setting events greater than 300ms.

This article references from: 1190000003848737

Http://liudong.me/web/touch-defect.html

Click through principle and solve

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.