zoukankan      html  css  js  c++  java
  • js移动端tap事件封装

    这几天做项目,发现移动端需要触摸事件,而click肯定是不行的,于是我对tap事件封装进行了搜索,找到了一篇文章,原文地址如下:http://www.jb51.net/article/50663.htm,

    我对其中第一个封装加了一点东西,把它封装在一个函数里面,使用的时候直接调用即可,源代码如下(tap.js):

    function tap(ele, fn){
        var startTx, startTy;
        var endTx, endTy;
        ele.addEventListener( 'touchstart', function( e ){
        var touches = e.touches[0];
        startTx = touches.clientX;
        startTy = touches.clientY;
    }, false );
    
    ele.addEventListener( 'touchend', function( e ){
        var touches = e.changedTouches[0];
        endTx = touches.clientX;
        endTy = touches.clientY;
        if( Math.abs(startTx - endTx) < 6 && Math.abs(startTy - endTy) < 6 ){
            fn(e);
        }
    }, false );
    }
    

      使用方法,引入js文件(即tap.js),然后执行如下调用:

    /*
        参数说明:
        ele:原生的dom对象
        fn :回调方法,执行你需要的操作    
    */
    
    tap(ele,function(e){
        //你需要执行的操作
    });    
    

      

  • 相关阅读:
    服务器错误日志
    IfcCurveBoundedSurface
    Ifc发展历史与版本介绍
    IfcCurveBoundedPlane
    IfcRationalBSplineSurfaceWithKnots
    IfcBSplineSurfaceWithKnots
    QDateTime QString
    IFC4 标准中的流程实体
    IFC 标准的定义
    MultipartFile
  • 原文地址:https://www.cnblogs.com/jiangbanji/p/6021702.html
Copyright © 2011-2022 走看看