zepto判斷左右滑動

    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("向右划動");  
                }  
            });  
相關文章
相關標籤/搜索