当前位置:网站首页>移动端双指缩放事件(原生),e.originalEvent.touches
移动端双指缩放事件(原生),e.originalEvent.touches
2022-07-26 10:24:00 【唐策】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>双指缩放事件</title>
</head>
<body>
<div class="full-bgimg">
</div>
<script> var pageX, pageY, initX, initY, isTouch = false; var start = []; $(".full-bgimg").on("touchstart",function(e){
// alert("touchstart") //手指按下时的手指所在的X,Y坐标 pageX = e.originalEvent.touches[0].pageX; pageY = e.originalEvent.touches[0].pageY; //初始位置的X,Y 坐标 initX = e.target.offsetLeft; initY = e.target.offsetTop; //记录初始 一组数据 作为缩放使用 if (e.originalEvent.touches.length >= 2) { //判断是否有两个点在屏幕上 start = e.originalEvent.touches; //得到第一组两个点 }; //表示手指已按下 // isTouch = true; }); $(".full-bgimg").on("touchmove",function(e){
e.preventDefault(); // 一根 手指 执行 目标元素移动 操作 if (e.originalEvent.touches.length == 1 && isTouch) {}; // 2 根 手指执行 目标元素放大操作 if (e.originalEvent.touches.length >= 2 && isTouch) { // alert("2") //得到第二组两个点 var now = e.originalEvent.touches; Math.abs(e.originalEvent.touches[0].pageX-e.originalEvent.touches[1].pageX) //当前距离变小, getDistance 是勾股定理的一个方法 if(getDistance(now[0], now[1]) < getDistance(start[0], start[1])){ }; }; }) $(".full-bgimg").on("touchend",function(e){
//将 isTouch 修改为false 表示 手指已经离开屏幕 // if (isTouch) {isTouch = false;} }); //缩放 勾股定理方法-求两点之间的距离 function getDistance(p1, p2) {
var x = p2.pageX - p1.pageX, y = p2.pageY - p1.pageY; return Math.sqrt((x * x) + (y * y)); }; </script>
</body>
</html>边栏推荐
- SPARK中 DS V2 push down(下推)的一些说明
- 汉诺塔II|汉诺塔4柱
- Okaleido生态核心权益OKA,尽在聚变Mining模式
- Prevent XSS attacks
- Function templates and non template functions with the same name cannot be overloaded (definition of overloads)
- Closure of go (cumulative sum)
- The fourth week of summer vacation
- Replay the snake game with C language (II) end
- Learning about tensor (III)
- Use of Android grendao database
猜你喜欢

Learning about tensorflow (I)

Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component

数通基础-STP原理

【Halcon视觉】数组

数通基础-网络基础知识

Learning about tensorflow (II)
![[Halcon vision] software programming ideas](/img/9b/a27338689ee4598dac88f6e5d92053.png)
[Halcon vision] software programming ideas

【Halcon视觉】形态学腐蚀

数据库的复习--3.SQL语言

点赞,《新程序员》电子书限时免费领啦!
随机推荐
The problem of incomplete or partial display of the last recyclerview is solved
AirTest
The CLOB field cannot be converted when querying Damon database
汉诺塔II|汉诺塔4柱
【Halcon视觉】图像的傅里叶变换
SQL Server 2008 R2 installation problems
【Halcon视觉】阈值分割
IEEE conference upload font problem
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
SQL优化的魅力!从 30248s 到 0.001s
【Halcon视觉】软件编程思路
Function templates and non template functions with the same name cannot be overloaded (definition of overloads)
抓包工具fiddler和wireshark对比
Basic usage of protobuf
Solution of inputting whole line string after inputting integer
数通基础-TCPIP参考模型
MLX90640 红外热成像仪测温传感器模块开发笔记(六)
Reproduce the snake game in C language (I) build pages and construct snakes
[Qualcomm][Network] qti服务分析
【Halcon视觉】仿射变换