zoukankan      html  css  js  c++  java
  • 滑动事件

    tachMove(item)
    function tachMove(targer){
        var startx,starty,X,Y;
        targer.addEventListener("touchstart",function(e){ //第一次触摸
            startx = e.touches[0].pageX;
            starty = e.touches[0].pageY;
        });
    
        targer.addEventListener("touchmove",function(e){ //手指屏幕滑动
                X = (e.touches[0].pageX) - startx;
                Y = (e.touches[0].pageY) - starty;
                //判断上下左右滑动
                if(  Math.abs(X) > Math.abs(Y) && X > 0 ){
                    toRight();
                }
                else if( Math.abs(X) > Math.abs(Y) && X < -12 ){
                    toLeft()
                }
                else if(  Math.abs(Y) > Math.abs(X) && Y > 12 ){
                    toBottom();
                }
                else if( Math.abs(Y) > Math.abs(X) && Y < -12 ){
                    toTop()
                }
            });
    }
    // 执行函数
    function toRight(){
        console.log("向右")
    }
    function toLeft(){
        console.log("向左")
    }
    function toBottom(){
        console.log("向下")
    }
    function toTop(){
        console.log("向上")
    }
  • 相关阅读:
    hdu 2227
    小A的数学题
    E
    F
    C
    Ping-Pong (Easy Version)的解析
    余数之和BZOJ1257
    大数求余
    数论学习 算法模板(质数,约数)
    Acwing 197. 阶乘分解
  • 原文地址:https://www.cnblogs.com/xm16/p/10265901.html
Copyright © 2011-2022 走看看