zoukankan      html  css  js  c++  java
  • 移动端-解决ios连续点击页面上移问题

    引入js即可

    //解决ios双击页面上移问题
    //在项目中测试不紧input/button这些表单控件有这个问题,p,div等也有问题,于是乎就直接在body开刀了
    (function()
    {
    var agent = navigator.userAgent.toLowerCase(); //检测是否是ios
    var iLastTouch = null; //缓存上一次tap的时间
    if (agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0)
    {
    document.body.addEventListener('touchend', function(event)
    {
    var iNow = new Date()
    .getTime();
    iLastTouch = iLastTouch || iNow + 1 /** 第一次时将iLastTouch设为当前时间+1 */ ;
    var delta = iNow - iLastTouch;
    if (delta < 500 && delta > 0)
    {
    event.preventDefault();
    return false;
    }
    iLastTouch = iNow;
    }, false);
    }

    })();

    //下面是国外coder给的解决方案
    //http://appcropolis.com/blog/howto/implementing-doubletap-on-iphones-and-ipads
    (function($){
    // Determine if we on iPhone or iPad
    var isiOS = false;
    var agent = navigator.userAgent.toLowerCase();
    if(agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0){
    isiOS = true;
    }

    $.fn.doubletap = function(onDoubleTapCallback, onTapCallback, delay){
    var eventName, action;
    delay = delay == null? 500 : delay;
    eventName = isiOS == true? 'touchend' : 'click';

    $(this).bind(eventName, function(event){
    var now = new Date().getTime();
    var lastTouch = $(this).data('lastTouch') || now + 1 /** the first time this will make delta a negative number */;
    var delta = now - lastTouch;
    clearTimeout(action);
    if(delta<500 && delta>0){
    if(onDoubleTapCallback != null && typeof onDoubleTapCallback == 'function'){
    onDoubleTapCallback(event);
    }
    }else{
    $(this).data('lastTouch', now);
    action = setTimeout(function(evt){
    if(onTapCallback != null && typeof onTapCallback == '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 500 ms) */
    400
    );
    //下面是国外coder给的解决方案--end
    //解决ios双击网面上移问题--end
  • 相关阅读:
    ListBox的数据绑定
    GridView中加入新行方法
    一个事务的例子
    用sql语句查询从N条到M条的记录
    用户注册表中日期输入的解决方案
    对分页控件进行分页的封装
    我的触发器
    缓存DataSet以提高性能
    网站访问统计在Global.asax中的配置
    给表格控件绑定数据库内容的封装
  • 原文地址:https://www.cnblogs.com/wang715100018066/p/6008371.html
Copyright © 2011-2022 走看看