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

zepto判断左右滑动

时间:2016-06-12 18:28:28      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:

    var startPosition, endPosition, deltaX, deltaY, moveLength;  
            $(".content").bind(‘touchstart‘, function(e){  
                var touch = e.touches[0];  
                startPosition = {  
                    x: touch.pageX,  
                    y: touch.pageY  
                }  
            }) .bind(‘touchmove‘, function(e){  
                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));  
            }).bind(‘touchend‘, function(e){  
                if(deltaX < 0) { // 向左划动  
                    console.log("向左划动");  
                } else if (deltaX > 0) { // 向右划动  
                    console.log("向右划动");  
                }  
            });  

 

zepto判断左右滑动

标签:

原文地址:http://www.cnblogs.com/mujinxinian/p/5578255.html

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