当前位置:网站首页>Mobile terminal click penetration
Mobile terminal click penetration
2022-06-27 15:55:00 【Xiaobai, a vegetable seller】
One 、 Preface
We learned in the last blog that there is a delay problem in the click event on the mobile terminal , We can take some measures , To solve 300ms Delay problem . Now let's think about ,click The event has a delay 300ms problem , We use... On the mobile end touchstart Can't we solve this problem by listening to events ?
The mobile end touchstart The incident also has some drawbacks :1、 If we want to swipe the phone screen , But at this time, the mobile phone will also be touched , triggering touchstart event 2.、touchstart The event has a click through problem .
Two 、 What is click through
If we have two elements A,B, This element B Element in A The upper , We listen to elements B Of touchstart event , When an event is triggered , We will B To hide . Then the element A It will trigger click event , If the element A For a link , The element A Will realize the jump . as a result of : When trigger element B Of touchstart When an event is , The process of triggering an event is :touchstart > touchend > click, This element B disappear , The browser will be in 300ms After the click Events are dispatched to elements in the same location . If at this point the element A Element in B Trigger touchstart In the same position as , The element... Is triggered A Of click event .
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="user-scalable">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.box1 {
width: 100%;
height: 500px;
background-color: red;
}
.box2 {
width:100%;
height: 200px;
background-color: green;
position: absolute;
z-index: 1111;
top: 0px;
}
</style>
<title>Document</title>
</head>
<body>
<div class="box1">
<a href="https://www.baidu.com"> use Baidu Search You will know </a>
<div class="box2"></div>
</div>
<script>
const box1 = document.querySelector(".box1")
const box2 = document.querySelector(".box2")
box2.addEventListener("touchstart", (e) => {
console.log(" Trigger box2 Ha ha ha ha ")
box2.style.display = "none"
})
box1.addEventListener("click", () => {
console.log(" Trigger box1 Hahaha ")
})
</script>
</body>
</html>
3、 ... and 、 Browser event trigger sequence
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
margin: 0px;
padding: 0px;
}
#app {
width: 100%;
height: 100px;
background-color: red;
}
</style>
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script>
const app = document.querySelector("#app")
app.addEventListener("touchstart", () => {
console.log(" Trigger touchstart event ")
})
app.addEventListener("mouseover", () => {
console.log(" Trigger mouseover event ")
})
app.addEventListener("mousemove", () => {
console.log(" Trigger mousemove event ")
})
app.addEventListener("mousedown", () => {
console.log(" Trigger mousedown event ")
})
app.addEventListener("mouseup", () => {
console.log(" Trigger mouseup event ")
})
app.addEventListener("touchmove", () => {
console.log(" Trigger touchmove event ")
})
app.addEventListener("touchend", () => {
console.log(" Trigger touchend event ")
})
app.addEventListener("click", () => {
console.log(" Trigger click event ")
})
</script>
</body>
</html>

The above is the sequence of events in the browser I tested , At this time, the order is :touchstart > touchend > mouseover > mousemove > mousedown > mouseup > clicktouchstart > touchmove > touchend
| event | describe | trigger |
|---|---|---|
| touchstart | Start touching | The finger touch screen immediately triggers |
| touchmove | Move or drag | Depending on the system and browser |
| touchend | End of touch | Finger leaving triggers immediately |
Four 、 What happened 1、 Click through question
Trigger... Under the mask touchstart Method , Disappearance of mask , Trigger... In this position click event .2、 Cross page click through question
Consistent with the above principle , There is one below a link , When the upper layer is triggered touchstart Method , Will trigger the same position click event , If a The link is below the current trigger position , Page Jump will be triggered .
5、 ... and 、 Solution 1、 Will all click All events are changed to touch event
Because some a The link uses click event , At this time, you can use the touchend and span The label is used in combination with .
2、 Don't use touch event , Use only click event
Only... Is used in the mobile browser click Events can cause 300ms The problem of delay , If our interactivity is not high, we can use , But still not recommended .3、 Block default events 
4、 introduce fastclick.js
边栏推荐
- 手机号码的格式
- Introduce you to ldbc SNB, a powerful tool for database performance and scenario testing
- Design of vga/lcd display controller based on FPGA (with code)
- Condom giants' sales have fallen by 40% in the past two years. What are the reasons for the decline?
- Sigkdd22 | graph generalization framework of graph neural network under the paradigm of "pre training, prompting and fine tuning"
- Pisa-Proxy 之 SQL 解析实践
- 3.1 simple condition judgment
- 16 -- remove invalid parentheses
- 一场分销裂变活动,不止是发发朋友圈这么简单!
- express
猜你喜欢

开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事

Leetcode daily practice (Yanghui triangle)

【Pygame小遊戲】這款“吃掉一切”遊戲簡直奇葩了?通通都吃掉嘛?(附源碼免費領)

#28对象方法扩展

Eolink launched a support program for small and medium-sized enterprises and start-ups to empower enterprises!

Introduction to TTCAN brick moving

Derivation of Halcon camera calibration principle

LeetCode每日一练(主要元素)
![Beginner level Luogu 2 [branch structure] problem list solution](/img/53/d7bf659f7e1047db4676c9a01fcb42.png)
Beginner level Luogu 2 [branch structure] problem list solution

2022-2-16 learning the imitated Niuke project - Section 6 adding comments
随机推荐
Gin general logging Middleware
洛谷_P1002 [NOIP2002 普及组] 过河卒_dp
Jialichuang EDA professional edition all offline client release
守护雪山之王:这些AI研究者找到了技术的新「用武之地」
【Pygame小游戏】这款“吃掉一切”游戏简直奇葩了?通通都吃掉嘛?(附源码免费领)
Difference between special invoice and ordinary invoice
SQL parsing practice of Pisa proxy
The role of the symbol @ in MySQL
Open source 23 things shardingsphere and database mesh have to say
关于TensorFlow使用GPU加速
实现简单的三D立方体自动旋转
3.1 simple condition judgment
If you want to use DMS to handle database permissions, can you only use Alibaba cloud ram accounts (Alibaba cloud RDS)
Taishan Office Technology Lecture: the first difficulty is vertical positioning
Does polardb-x currently not support self-made database service Das?
16 -- remove invalid parentheses
Indexeddb learning materials
PolarDB-X开源版有没有支持 mysql5.7 的版本?
Nemo of pulseaudio (22)
Pisa-Proxy 之 SQL 解析实践