Mobile page click through problem solution

Source: Internet
Author: User
<span id="Label3"></p>Mobile page click through problem solution<span class="timestamp" style="margin-right:5px"><span class="timestamp" style="margin-right:5px">Time 2015-08-24 21:43:58</span></span><span class="from" style="margin-right:5px"><span class="from" style="margin-right:5px"> <span class="icon-globe" style=""></span> Dim Feather Breeze</span></span><span style="float:left"><span style="float:left">Original</span></span>Http://www.ayqy.net/blog/mobile page Click to penetrate the problem solution/<span style="margin-right:5px"><span style="margin-right:5px">Theme</span></span><span class="new-label" style="display:inline-block; padding:2px 4px; font-size:0.9em; line-height:16px; vertical-align:baseline; white-space:nowrap; color:rgb(120,120,120); margin-right:5px; background-color:rgb(242,242,242)"><span class="new-label" style="display:inline-block; padding:2px 4px; font-size:0.9em; line-height:16px; vertical-align:baseline; white-space:nowrap; color:rgb(120,120,120); margin-right:5px; background-color:rgb(242,242,242)">JavaScript</span></span>ONE. Click and 300ms delay<p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">The mobile browser provides a special feature: double tap to enlarge</p></p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">The delay of 300ms comes from here, after the user touches the page, it takes a while to decide if it is a double tap action instead of an immediate response click, and the time to wait is about 300MS. There was a brief introduction: breeze: HTML5 Touch Event</p></p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">The Move event provides<code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)"><code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)">touchstart</code></code>、<code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)"><code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)">touchmove</code></code>、<code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)"><code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)">touchend</code></code>Without tap support, The mainstream framework (library) implements custom tap events manually in order to eliminate 300MS latency and improve page response Times. For a simple page, you can put<code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)"><code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)">touchstart</code></code>Or<code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)"><code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)">touchend</code></code>Used as a tap, but there are some problems, such as the finger touch the target element, Press and hold, slowly move out of the response area, will trigger<code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)"><code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)">touchstart</code></code>Event execution corresponding to the event handler (this should not be triggered),<code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)"><code style="padding:2px 4px; font-family:Monaco,Menlo,Consolas,‘Courier New‘,monospace; border:none; background-color:rgb(247,247,249)">touchend</code></code>There are similar problems with Events.</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">In addition, there is a <em>click-through problem with native touch events</em> , because click is triggered about 300ms after the touch series event, and mixing touch and click will definitely cause a point-through problem, which is described in detail below</p></p>Two. Click through problems<p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">There are 3 types of Click-through Phenomena:</p></p> <ul style="padding:0px; margin:0px 0px 0.75em 25px; list-style-type:none; line-height:1.7em"> <li style="line-height:1.7em; list-style-type:disc"><li style="line-height:1.7em; list-style-type:disc"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em">Click to penetrate the Problem: click the Close button on the mask, the mask disappears after the Click event that triggered the element below the button</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em">The Mask's Close button binds to the touch event, and the button below binds the click event, and after the touch event is triggered, the mask disappears, and the target of the Click event of the fire,event after 300ms is naturally the element below the Button. Because the button disappeared with the Mask.</p></li></li> <li style="line-height:1.7em; list-style-type:disc"><li style="line-height:1.7em; list-style-type:disc"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em">Cross-page Click through problem: If the button below is exactly a tag with an href attribute, then the page will jump</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em">Because the <em>a tag jumps by default is the Click event Trigger</em> , so the principle is exactly the same as above</p></li></li> <li style="line-height:1.7em; list-style-type:disc"><li style="line-height:1.7em; list-style-type:disc"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em">Another cross-page click through the problem: this time there is no mask, directly click on the page button to jump to the new page, and then found that the new page in the corresponding location element of the Click event is triggered</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em">And the truth of the mask, JS control page Jump Logic if it is bound on the touch event, and the new page corresponding to the location of the element binding is the click event, and the page in 300ms to complete the jump, three conditions at the same time to meet, this is the case</p></li></li> </ul><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Not to subdivide the words there is a fourth, but the probability is very low, is the new page corresponding to the location element is a tag, and then the occurrence of a continuous jump ... And all that, It's a click-through problem.</p></p>Three. Solution<p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">The problem is clear, there are many solutions, but there are 2 ways of thinking:</p></p> <ol style="padding:0px; margin:0px 0px 0.75em 25px; line-height:1.7em"> <ol style="padding:0px; margin:0px 0px 0.75em 25px; line-height:1.7em"> <li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Don't mix touch and click</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Since touch 300ms triggers the click, only touch or just click will naturally have no problem.</p></li> <li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Eat (or Consume) the click after touch</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Still use tap, just in the case of possible click through the situation to do extra processing, take something to block, or tap delay after 350 milliseconds to hide mask, pointer-events, in the following element of the event handler for detection (with global Flag) and so on, can eat on the line</p></li> </ol> </ol><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Detailed solution:</p></p> <ol style="padding:0px; margin:0px 0px 0.75em 25px; line-height:1.7em"> <li style="line-height:1.7em"><li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"> with touch only </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"> The simplest solution that perfectly solves the Click-through problem </p> <p style="padding:2px 4px; font-family:monaco,menlo,consolas, ' Courier New ', monospace; border:none; Background-color:rgb (247,247,249) " to switch all the click in page touch event (  <code>touchstart  , ' touchend ', ' tap '), <em> requires special attention to the </em>  a tag, A tag of the href is also click, you need to remove the jump to JS control, or directly to the span + tap control Jump. If the requirements are not high, do not care to slip or slip in to trigger events, span + touchend can be, after all, tap needs to introduce a Third-party library </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; Text-indent:1em "> without a tag actually nothing, mobile app development does not consider seo, even with a tag, generally will remove all default styles, rather than directly with the span </p> </li></li> <li style="line-height:1.7em"><li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Use only click</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><em>The worst-case scenario</em> , because of the 300ms delay, any custom interaction on the page will increase by 300 milliseconds delay, think all slow</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Without touch there will be no touch 300ms trigger Click problem, If the interactivity is not high can do so, <em>strongly not recommended</em> , fast is always good</p></li></li> <li style="line-height:1.7em"><li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Get something to block it.</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">It's a stupid way, <em>don't use</em> it.</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Leaves "chrysanthemum" dafa, For more information please see "research on mobile compatibility" JavaScript event mechanism (involving Mobile Compatibility)</p></li></li> <li style="line-height:1.7em"><li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">tap delay 3 50ms again hides the mask </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"> minimal changes, The downside is that the hide mask slows down, and the 350ms can still feel the slow </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em" only needs to be handled for mask, the changes are very small, if requirement is not high, use this less effort < p> </p></li></li> <li style="line-height:1.7em"><li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">pointer -events </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"> more troublesome and flawed,  <em> Not recommended </em> </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">mask after hiding, add  < to the element below the button Code style= "padding:2px 4px; font-family:monaco,menlo,consolas, ' Courier New ', monospace; border:none; Background-color:rgb (247,247,249) ">pointer-events:none;   style, Let click through the past, 350ms after the removal of this style, recovery response </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; Text-indent:1em "> The flaw is that the mask disappears after the 350ms, the user can see the button below the element point is not responding, if the user is fast, you will find the </p> </li></li> <li style="line-height:1.7em"><li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"> What's in the following element (with Global Flag) </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"> more trouble ,   <em> not recommended </em> </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"> Global flag Record button click Position (coordinate point), in the following element of the event handler to determine the coordinates of the event, if the same is the hateful click, refused to respond to </p> <p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; Text-indent:1em "> above is just the idea, not tested, it is not possible to use record time stamp judgment, waiting for 350ms, so and  <code style=" padding:2px 4px; font-family:monaco,menlo,consolas, ' Courier New ', monospace; border:none; Background-color:rgb (247,247,249) ">pointer-events </code>   almost </p> </li></li> <li style="line-height:1.7em"><li style="line-height:1.7em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Fastclick</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Easy to use solution, do not mind to load a few kb, <em>not recommended</em> , because someone encountered a bug, more information please see: Fastclick causes the Click event to fire two times the problem</p><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">First introduce the Fastclick library, and then the page all the touch events are replaced by click, in fact, a little bit of trouble, it is recommended to introduce these several KB in order to solve the problem is not worth, instead of using the first method</p></li></li> </ol>Four. DEMO<p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em"><p style="margin-top:0px; margin-bottom:0.75em; line-height:1.7em; text-indent:1em">Write a lot of test page, please check: <span class="__cf_email__" data-cfemail="04436d70444b5747">[email protected]</span> ayqy/my.js</p></p>Resources <ul style="padding:0px; margin:0px 0px 0.75em 25px; list-style-type:none; line-height:1.7em"> <ul style="padding:0px; margin:0px 0px 0.75em 25px; list-style-type:none; line-height:1.7em"> <li style="line-height:1.7em; list-style-type:disc">Some of the seniors ' posts</li> </ul> </ul><p><p>Mobile page click through problem solution</p></p></span>

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.