滑动事件

var startPosition,endPosition,deltaX,deltaY,moveLength,;
        $(".cover").on('touchstart', function(e){
            e.preventDefault();
            var touch = e.touches[0];
            startPosition = {
                x: touch.pageX,
                y: touch.pageY
            }
        }).on('touchmove', function(e){
            e.preventDefault();
            var touch = e.touches[0];
            endPosition = {
                x: touch.pageX,
                y: touch.pageY
            };
            deltaX = endPosition.x - startPosition.x;
            deltaY = endPosition.y - startPosition.y;
            //moveLength = Math.sqrt(Math.pow(Math.abs(deltaX), 2) + Math.pow(Math.abs(deltaY), 2));
        }).on('touchend', function(e){
            e.preventDefault();
            if(deltaY < -50) { // 向上划动
                $('.wrap').css({
                    "-webkit-transform": "translate3d(0, -100%, 0)"
                });
                startPosition=null;
                endPosition=null;
                deltaX=0;
                deltaY=0;
            } else if (deltaY > 0) { // 向下划动

            }
        });

  

posted @ 2017-06-05 19:23  xiangcy  阅读(194)  评论(0编辑  收藏  举报