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("向右划动");
                }
            });  
时间: 2024-08-10 23:15:40

zepto判断左右滑动的相关文章

《移动端浏览器Touch事件判断手指滑动方向方法》

1 $("body").on("touchstart", function(e) { 2     e.preventDefault(); 3     startX = e.originalEvent.changedTouches[0].pageX, 4     startY = e.originalEvent.changedTouches[0].pageY; 5 }); 6 $("body").on("touchmove",

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) } }

android android 判断是否滑动

(转自:http://blog.csdn.net/angle_rupert/article/details/6255522) 声明: 1 float x_temp01 = 0.0f; 2 float y_temp01 = 0.0f; 3 float x_temp02 = 0.0f; 4 float y_temp02 = 0.0f; 重写Activity的onTouchEvent方法: 1 @Override 2 public boolean onTouchEvent(MotionEvent ev

zepto判断手机横竖屏

var CheckOrientation = (function(){ var win = $( window ), get_orientation, last_orientation, initial_orientation_is_landscape, initial_orientation_is_default, portrait_map = { "0": true, "180": true }, ww, wh, landscape_threshold; if(

Android 判断ListView滑动方向

代码很简单,给mListView监听onScrollListener事件,然后在onScroll进行判断 //listView中第一项的索引 private int mListViewFirstItem = 0; //listView中第一项的在屏幕中的位置 private int mScreenY = 0; //是否向上滚动 private boolean mIsScrollToUp = false; @Override public void onScroll(AbsListView abs

基于zepto判断mobile的横竖屏状态

借用jquery mobile中的代码,删除了一些多余的部分,简单的基于zepto的模块 var CheckOrientation = (function(){ var win = $( window ), get_orientation, last_orientation, initial_orientation_is_landscape, initial_orientation_is_default, portrait_map = { "0": true, "180&qu

android 判断左右滑动,上下滑动的GestureDetector简单手势检测

直接加入监听GestureDetector放在需要判断滑动手势的地方: 1 import android.app.Activity; 2 import android.os.Bundle; 3 import android.util.Log; 4 import android.view.GestureDetector; 5 import android.view.GestureDetector.OnGestureListener; 6 import android.view.MotionEven

判断listview滑动方向的代码片段

mListView.setOnScrollListener(new OnScrollListener() { private int lastIndex = 0; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // TODO 自动生成的方法存根 switch (scrollState) { // 滚动之前,手还在屏幕上 记录滚动前的下标 case OnScrollListener.S

js判断元素滑动方向(上下左右)移动端

每天学习一点点. 1 var startx, starty; 2 //获得角度 3 function getAngle(angx, angy) { 4 return Math.atan2(angy, angx) * 180 / Math.PI; 5 }; 6 7 //根据起点终点返回方向 1向上 2向下 3向左 4向右 0未滑动 8 function getDirection(startx, starty, endx, endy) { 9 var angx = endx - startx; 10