touchstart,touchmove判断手机中滑屏方向
来源:互联网 发布:ubuntu server配置 编辑:程序博客网 时间:2024/06/18 08:23
滑动屏幕 touchstart:接触屏幕时触发,touchmove:活动过程触发,touchend:离开屏幕时触发
首先获取手接触屏幕时的坐标X,Y
//获取接触屏幕时的X和Y
$('body').bind('touchstart',function(e){ startX = e.originalEvent.changedTouches[0].pageX, startY = e.originalEvent.changedTouches[0].pageY;});
然后获取滑动的坐标,并使用后面的坐标减去前面的坐标,通过获取的值判断其滑动方向。因为手滑动方向一般不是水平或者垂直的,所以可使用Math.abs()进行比较,比如:像右上角滑动,当往上滑动的距离大于往右的距离时,取其往上滑动的距离,即往上滑动。
$('body').bind('touchmove',function(e){ //获取滑动屏幕时的X,Y endX = e.originalEvent.changedTouches[0].pageX, endY = e.originalEvent.changedTouches[0].pageY; //获取滑动距离 distanceX = endX-startX; distanceY = endY-startY; //判断滑动方向 if(Math.abs(distanceX)>Math.abs(distanceY) && distanceX>0){ console.log('往右滑动'); }else if(Math.abs(distanceX)>Math.abs(distanceY) && distanceX<0){ console.log('往左滑动'); }else if(Math.abs(distanceX)<Math.abs(distanceY) && distanceY<0){ console.log('往上滑动'); }else if(Math.abs(distanceX)<Math.abs(distanceY) && distanceY>0){ console.log('往下滑动'); }else{ console.log('点击未滑动'); }});
阅读全文
0 0
- touchstart,touchmove判断手机中滑屏方向
- H5 touchstart、touchmove、touchend 拖拽
- 触摸三事件touchstart,touchend,touchmove
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- jQuery touchstart,touchmove,touchend 获取位置
- 【HTML5】触摸事件(touchstart、touchmove和touchend)
- touchstart ,touchmove, touchend 页面随手指滑动
- 触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- h5触摸事件:touchstart、touchmove和touchend
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- 安装MeadCo ScriptX的ActiveX控件
- Java 中接口为什么可以调用 toString 方法,接口中根本就没有 toString 方法?
- java——深入java.util包(collection接口之AbstractList)
- kafka-架构(详解)
- iOS对存放对象的数组排序
- touchstart,touchmove判断手机中滑屏方向
- 提高 service 存活率
- SEI各种语法以及SEI消息在解码、显示或其它过程中起辅助作用
- HBase 创建表预分区
- java中正则匹配的贪婪模式和非贪婪模式
- DistMesh
- Android studio编译报错:Error:Execution failed for task ':app:transformClassesWithDexForDebug'
- 121Best Time to Buy and Sell Stock
- 支持向量机(SVM):基本原理