Fix iOS Double-click Page UP problem

Source: Internet
Author: User

When doing WebApp, iOS has a default double-click event, which will zoom the page and center the current click to the screen, it is nothing, but when the page has fixed positioning elements, then you will magically find that the fixed element can not be obtained!

What's more, the page will move up ...

//fix iOS Double-click Page UP Problem//testing in the project is not tight Input/button These form controls have this problem, p,div and so on have problems, and then directly in the body surgery(function(){    varAgent = Navigator.userAgent.toLowerCase ();//detect if it is iOS    varIlasttouch =NULL;//cache The time of the last tap    if(Agent.indexof (' iphone ') >= 0 | | agent.indexof (' ipad ') >= 0) {Document.body.addEventListener (' Touchend ',function(event) {varInow =NewDate (). GetTime (); Ilasttouch= Ilasttouch | | Inow + 1/** Ilasttouch is set to the current time for the first time +1*/ ; varDelta = inow-Ilasttouch; if(Delta < && Delta > 0) {event.preventdefault (); return false; } Ilasttouch=Inow; }, false); }})();//The following is a solution given by foreign coder
Http://appcropolis.com/blog/howto/implementing-doubletap-on-iphones-and-ipads
(function($){    //determine if we on IPhone or IPad    varIsios =false; varAgent =navigator.userAgent.toLowerCase (); if(Agent.indexof (' iphone ') >= 0 | | agent.indexof (' ipad ') >= 0) {Isios=true; } $.fn.doubletap=function(Ondoubletapcallback, ontapcallback, delay) {varEventName, Action; Delay= Delay = =NULL? 500: Delay; EventName= Isios = =true? ' Touchend ': ' Click '; $( This). Bind (EventName,function(event) {varnow =NewDate (). GetTime (); varLasttouch = $ ( This). Data (' Lasttouch ') | | Now + 1/** The first time this would make delta a negative number*/; varDelta = Now-Lasttouch;            Cleartimeout (action); if(delta<500 && delta>0){                if(Ondoubletapcallback! =NULL&&typeofOndoubletapcallback = = ' function ') {Ondoubletapcallback (event); }            }Else{                $( This). Data (' Lasttouch ', now); Action= SetTimeout (function(evt) {if(Ontapcallback! =NULL&&typeofOntapcallback = = ' function ') {ontapcallback (evt);   } cleartimeout (action); //Clear the timeout}, delay, [event]); }            $( This). Data (' Lasttouch ', now);    }); };}) (Zepto);//Usage:$ (selector). Doubletap (/** Doubletap-dblclick Callback*/    function(Event) {alert (' Double-tap '); },    /** Touch-click Callback (Touch)*/    function(Event) {alert (' Single-tap '); },    /** Doubletap-dblclick Delay (default is MS)*/400);//The following is a solution given by foreign coder--end//troubleshoot iOS double-click on the mesh move problem--end

Fix iOS Double-click Page UP problem

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.