码迷,mamicode.com
首页 > 其他好文 > 详细

滑动事件

时间:2017-06-05 20:00:26      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:class   tran   highlight   pagex   事件   tde   blog   end   else   

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) { // 向下划动

            }
        });

  

滑动事件

标签:class   tran   highlight   pagex   事件   tde   blog   end   else   

原文地址:http://www.cnblogs.com/mbyund/p/6946663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!