• h5触摸事件-判断上下滑动


            // 判断上下滑动
            var startX = 0,
            startY = 0;
        function touchStart(evt){
            try{
                var touch = evt.touches[0], //获取第一个触点
                        x = Number(touch.pageX), //页面触点X坐标
                        y = Number(touch.pageY); //页面触点Y坐标
                //记录触点初始位置
                startX = x;
                startY = y;
            }catch(e){
                console.log(e.message)
            }
        }
    
        function touchMove(evt){
            try{
                var touch = evt.touches[0], //获取第一个触点
                        x = Number(touch.pageX), //页面触点X坐标
                        y = Number(touch.pageY); //页面触点Y坐标
                //判断滑动方向
                if (y - startY<0) {
                    console.log('上滑了!');
                    var mainView = myApp.addView('.view-main', {domCache: true});
                    mainView.router.load({pageName: 'friendCircle'});
                }
            }catch(e){
                console.log(e.message);
            }
        }
    
        // function touchEnd(evt){
        //     try{
        //         var touch = evt.touches[0], //获取第一个触点
        //                 x = Number(touch.pageX), //页面触点X坐标
        //                 y = Number(touch.pageY); //页面触点Y坐标
        //         //判断滑动方向
        //         if (y - startY<0) {
        //             console.log('上滑了!');
        //         }
        //     }catch(e){
        //         console.log(e.message);
        //         console.log("end");
        //     }
        // }
    
        //绑定事件
        function bindEvent(){
            document.addEventListener('touchstart',touchStart,false);
            document.addEventListener('touchmove',touchMove,false);
            // document.addEventListener('touchend',touchEnd,false);
        }
    
    
        bindEvent();

    参考:http://blog.csdn.net/bbsyi/article/details/52108599

  • 相关阅读:
    函数宏实现循环左移
    函数宏判断小端
    Linux下32位与64位数据类型大小
    转:C语言嵌入式系统编程之软件架构篇
    转:详解大端小段模式
    time函数计算时间
    匈牙利命名法
    20131030
    20131029
    20131028
  • 原文地址:https://www.cnblogs.com/zhenguoli/p/7594572.html
Copyright © 2020-2023  润新知