当前位置:网站首页>DOM series of touch screen events
DOM series of touch screen events
2022-08-01 16:02:00 【Old __L】
Directory
1. Overview of touch screen events
The compatibility of mobile browsers is good. We don't need to consider the compatibility of previous JS, and we can use native JS writing effects with confidence, but the mobile terminal also has its own unique features.For example, the touch screen event touch (also called touch event), both Android and IOS have.
Thetouch object represents a touch point.The touch point may be a finger or a stylus.Touch events respond to user finger (or stylus) operations on the screen or trackpad.
2. Common touch screen events
3. TouchEvent Object (TouchEvent)
TouchEvent is a class of events that describe the state change of a finger on a touch plane (touch screen, touchpad, etc.).This type of event is used to describe one or more touchpoints, allowing developers to detect movement of touchpoints, increase and decrease of touchpoints, etc.
The three events touchstart, touchmove, and touchend will have their own event objects.
Touch Event Objects Focus on a list of three common objects:
Because we usually register touch events for elements, so focus on remembering targetTocuhes
4. Drag elements on the mobile side
- touchstart, touchmove, touchend can drag elements;
- But dragging the element needs the coordinate value of the current finger, we can use pageX and pageY in targetTouches[0];
- Principle of dragging on the mobile terminal: When the finger is moving, the distance the finger moves is calculated.Then use the original position of the box + the distance moved by the finger;
- The distance the finger moves: the position in the slide of the finger minus the position where the finger just started to touch;
4.1. Triad of dragging elements
(1), touch element touchstart: get the initial coordinates of the finger, and at the same time get the original position of the box;
(2) move the finger touchmove: calculate the sliding distance of the finger, and move the box;
(3) leaveFinger touchend:
Note: finger movement will also trigger scrolling, so here to prevent the default screen scrolling
e.preventDefault()
;
Afterword
If you feel that the article is not good
//(ㄒoㄒ)//
, leave a message in the comments, the author will continue to improve;o_O???
If you think the article is a little useful, you can give the author a like;\\*^o^*//
If you want to make progress with the author, you can Scan the QR code on WeChat and follow the front-end old L;~~~///(^v^)\\\~~~
Thank you readers(^_^)∠※
!!!
边栏推荐
- Can MySQL do two-way synchronization of multiple vps?
- 引用js报错$ is not defined解决办法
- MySQL中字符串比较大小(日期字符串比较问题)
- 时序数据库在船舶风险管理领域的应用
- "Find nearby shops" | Geohash+MySQL realizes geographic location filtering
- MySQL【创建和管理表】
- SSM入门
- Ranking of itineraries (summer vacation daily question 12)
- 指针进阶(三)之指针与数组笔试题
- MySQL可以做多台vps的双向同步吗?
猜你喜欢
随机推荐
Spark: Cluster Computing with Working Sets
全网最全音视频媒体流
VIM实用指南(3)复制,粘贴 ,删除,撤销,重做指令速记
SyntaxHighlighter带来的字符转义问题
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
如何有效地开发 Jmix 扩展组件
what is tail tooth feast
Next-ViT学习笔记
p5js炫酷网页流光动画
hzero-resource秒退
c语言rand函数生成随机数,详解C语言生成随机数rand函数的用法[通俗易懂]
gconf/dconf实战编程(2)利用gconf库读写配置实战以及诸多配套工具演示
May 20, 2022 The most complete fish game navigation
在网站页脚增加几只戏水的小鱼
Row locks in MySQL
lombok builder重写
LeetCode50天刷题计划(Day 10—— 三数之和(20.50-22.40)
LeetCode50天刷题计划(Day 8—— 盛最多水的容器(23.00-1.20)
2.8K 120Hz触控双屏加持 灵耀X 双屏Pro 2022让办公无惧想象
SSM入门