zoukankan      html  css  js  c++  java
  • 移动端,判断滑动方向

    直接看代码:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <title>移动端,判断滑动方向</title>
        <script src="http://apps.bdimg.com/libs/jquery/1.10.1/jquery.min.js"></script>
    </head>
    
    <body> 
        <script type="text/javascript">
    		var windowHeight = $(window).height();
    		$("body").css("height", windowHeight);
    		var startX, startY, moveEndX, moveEndY, X, Y;
    		$("body").on("touchstart", function(e) {
    			e.preventDefault();
    			startX = e.originalEvent.changedTouches[0].pageX, startY = e.originalEvent.changedTouches[0].pageY;
    		});
    		$("body").on("touchmove", function(e) {
    			e.preventDefault();
    			moveEndX = e.originalEvent.changedTouches[0].pageX, moveEndY = e.originalEvent.changedTouches[0].pageY, X = moveEndX - startX, Y = moveEndY - startY;
    			if (Math.abs(X) > Math.abs(Y) && X > 0) {
    				alert("left to right");
    			} else if (Math.abs(X) > Math.abs(Y) && X < 0) {
    				alert("right to left");
    			} else if (Math.abs(Y) > Math.abs(X) && Y > 0) {
    				alert("top to bottom");
    			} else if (Math.abs(Y) > Math.abs(X) && Y < 0) {
    				alert("bottom to top");
    			} else {
    				alert("just touch");
    			}
    		});
        </script>
    </body>
    
    </html>
    

      

  • 相关阅读:
    一个通用的事件监听函数全集
    单应性矩阵
    opencv姿态估计
    opencv相机标定
    Harris角点
    盒滤波Box Filter
    win10+vs2015+pcl1.8.1安装配置
    图像元素遍历
    阈值分割
    二叉树的层次遍历
  • 原文地址:https://www.cnblogs.com/jone-chen/p/6118930.html
Copyright © 2011-2022 走看看