当前位置:网站首页>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';
})边栏推荐
- 数据库范式和主码的选择
- Leetcode 238 product of arrays other than itself
- Redis Basics
- NFTGameFi链游系统开发详解方案丨链游系统开发原理解析
- 零时科技 | 智能合约安全系列文章之反编译篇
- 转:苹果CEO库克:伟大的想法来自不断拒绝接受现状
- 50 lines of code to crawl TOP500 books and import TXT documents
- Kubernetes resource topology aware scheduling optimization
- Unit test of boot
- The goal you specified requires a project to execute but there is no POM
猜你喜欢

CLion断点单步调试

The successfully resolved idea cannot use the log normally after referencing Lombok's @slf4j

Basic and necessary common plug-ins of vscade

Yujun product methodology

Commodity seckill system

Do you know how to compare two objects

爬取豆瓣读书Top250,导入sqlist数据库(或excel表格)中

Unit test of boot

微服务版单点登陆系统(SSO)

Wechat applet uniapp left slide delete with Delete Icon
随机推荐
Example of using QPushButton style (and method of adding drop-down menu to button SetMenu)
交叉编译环境出现.so链接文件找不到问题
Redis single sign on system + voting system
String string is converted to jsonarray and parsed
最小生成树、最短路径、拓扑排序、关键路径
ROS query topic specific content common instructions
DAPP丨LP单双币流动性质押挖矿系统开发原理分析及源码
Feign remote call
Xlua get button registration click event of ugui
mysql的充值问题
Nftgamefi chain game system development detailed solution - chain game system development principle analysis
Résolution du problème: la machine virtuelle n'a pas pu copier et coller le fichier
【Mysql系列】工作常用sql集锦(持续更新)
Commodity seckill system
IK分词器
sql 中的alter操作总结
Boot指标监测
Vscode 基础必备 常用插件
Leetcode 238 product of arrays other than itself
Solidity - contract inheritance sub contract contains constructor errors and one contract calls the view function of another contract to charge gas fees