zoukankan      html  css  js  c++  java
  • tap方法改良this指向

    /*封装tap*/
        function tap(dom,callback){
            /*
             * 要求  没有触发 touchmove 事件
             *       并且响应速度要比click快
             */
            if(dom && typeof  dom == 'object'){
                var isMove = false;
                var startTime = 0;
                dom.addEventListener('touchstart',function(e){
                    //console.log('touchstart');
                    //console.time('tap');/*记录tap这个参数现在的时间*/
                    startTime = Date.now();
                });
                dom.addEventListener('touchmove',function(e){
                    //console.log('touchmove');
                    isMove = true;
                });
                dom.addEventListener('touchend',function(e){
                    //console.log('touchend');
                    //console.timeEnd('tap')/*打印tap这个参数距离上一次记录的时候的时间*/
                    /*判读  是否满足tap 的要求  一般要求tap的响应时间150*/
                    if(!isMove && (Date.now()-startTime) < 150){
                        /*调用 callback*/
                        // callback && callback(e);
                        callback.call(dom, e);
                    }
                    /*重置 参数*/
                    isMove = false;
                    startTime = 0;
                });
            }
        }
  • 相关阅读:
    BZOJ1208
    BZOJ1024
    BZOJ_day4&&DSFZ_day1
    BZOJ day2_plus
    BZOJ day2
    系统设计2:数据库设计
    设计模式8:外观模式
    系统设计1:概述
    设计模式7:模板方法模式
    九章算法班ladder题目梳理
  • 原文地址:https://www.cnblogs.com/handsome-jm/p/7280996.html
Copyright © 2011-2022 走看看