当前位置:网站首页>JS mobile terminal touch screen event
JS mobile terminal touch screen event
2022-06-26 18:57:00 【MyDreamingCode】
One 、 Mobile touch screen events
1. touchstart: Touch the screen with your finger
document.addEventListener('touchstart',function() {
console.log('I touch you');
})
2. touchmove: Fingers sliding on the screen
document.addEventListener('touchmove',function() {
console.log('move');
})
3. touchend: Fingers off the screen
document.addEventListener('touchend',function() {
console.log('leave');
})
Two 、TouchEvent Touch the event object
1. touches: A list of all fingers that are touching the screen
2. targetTouches: Being touched DOM List of fingers on the element ( Use more )
3. changedTouches: List of finger states that have changed
3、 ... and 、 Drag element cases
var box = document.querySelector('.box');
var oddX = 0;
var oddY = 0;
var x = 0;
var y = 0;
box.addEventListener('touchstart', function(e) {
oddX = e.targetTouches[0].pageX;
oddY = e.targetTouches[0].pageY;
x = this.offsetLeft;
y = this.offsetTop;
})
box.addEventListener('touchmove', function(e) {
e.preventDefault(); // Prevent scrolling the screen
var moveX = e.targetTouches[0].pageX - oddX;
var moveY = e.targetTouches[0].pageY - oddY;
this.style.left = x + moveX + 'px';
this.style.top = y + moveY + 'px';
})
边栏推荐
- Decompilation of zero time technology smart contract security series articles
- DAPP丨LP单双币流动性质押挖矿系统开发原理分析及源码
- 問題解决:虛擬機無法複制粘貼文件
- 知识点总结
- Jsonutils tool class (based on Alibaba fastjson)
- Clion breakpoint single step debugging
- 为什么我不推荐去SAP培训机构参加培训?
- Record of user behavior log in SSO microservice Engineering
- 成功解决之Jenkins报错:The goal you specified requires a project to execute but there is no POM
- Procedure steps for burning a disc
猜你喜欢
Microservice architecture
50 lines of code to crawl TOP500 books and import TXT documents
商品秒杀系统
Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems
Feign remote call
Clion breakpoint single step debugging
项目实战五:搭建ELk日志收集系统
限流设计及实现
ARM裸板调试之串口打印及栈初步分析
项目实战四:用户登录及token访问验证(reids+jwt)
随机推荐
Leetcode 238 product of arrays other than itself
【Mysql系列】工作常用sql集锦(持续更新)
To: seek truth from facts
Development principle analysis and source code of dapp-lp single and dual currency liquidity pledge mining system
微信小程序 uniapp 左滑 删除 带删除icon
限流设计及实现
预编译处理指令中的条件编译
品达通用权限系统(Day 1~Day 2)
Minimum spanning tree, shortest path, topology sorting, critical path
Request method 'POST' not supported
Summary of several common UML diagrams
读书笔记:《过程咨询 III》
项目实战五:搭建ELk日志收集系统
The goal you specified requires a project to execute but there is no POM
50 lines of code to crawl TOP500 books and import TXT documents
软考备战多媒体系统
Yujun product methodology
On the escape of inequality value
9. Intelligent transportation project (2)
Project practice 5: build elk log collection system