当前位置:网站首页>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
边栏推荐
- 2022年最新《谷粒学院开发教程》:8 - 前台登录功能
- Weekly snapshot of substrate technology 20220411
- Design of electronic calculator system based on FPGA (with code)
- 机械硬盘和ssd固态硬盘的原理对比分析
- Admixture usage document Cookbook
- PSS:你距离NMS-free+提点只有两个卷积层 | 2021论文
- SIGKDD22|图“预训练、提示、微调”范式下的图神经网络泛化框架
- Design of UART controller based on FPGA (with code)
- Mode setting of pulseaudio (21)
- 如果想用dms来处理数据库权限问题,想问下账号只能用阿里云的ram账号吗(阿里云的rds)
猜你喜欢

The interview lasted for half a year. Last month, I successfully got Alibaba p7offer. It was all because I chewed the latest interview questions in 2020!

关于TensorFlow使用GPU加速

Leetcode daily practice (main elements)

Distributed session solution

【Pygame小游戏】这款“吃掉一切”游戏简直奇葩了?通通都吃掉嘛?(附源码免费领)

List转Table

Eolink 推出面向中小企业及初创企业支持计划,为企业赋能!

ICML 2022 | 阿⾥达摩院最新FEDformer,⻓程时序预测全⾯超越SOTA

一场分销裂变活动,不止是发发朋友圈这么简单!

3.3 one of the fixed number of cycles
随机推荐
Introduce you to ldbc SNB, a powerful tool for database performance and scenario testing
List转Table
What is the open source compatibility of the current version of polardb-x? mysql8?
洛谷入门2【分支结构】题单题解
熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
2022-2-16 learning the imitated Niuke project - Section 6 adding comments
16 -- remove invalid parentheses
Piblup test report 1- pedigree based animal model
[issue 17] golang's one-year experience in developing Meitu
Design of FIR digital filter
CentOS8-postgresql初始化时报错:initdb: error: invalid locale settings; check LANG and LC_* environment
Jialichuang EDA professional edition all offline client release
3.4 fixed number of cycles II
A distribution fission activity is more than just a circle of friends!
【Pygame小游戏】这款“吃掉一切”游戏简直奇葩了?通通都吃掉嘛?(附源码免费领)
Eolink 推出面向中小企业及初创企业支持计划,为企业赋能!
2022-2-15 learning the imitated Niuke project - Section 5 shows comments
[pyGame games] this "eat everything" game is really wonderful? Eat them all? (with source code for free)
PSS:你距離NMS-free+提點只有兩個卷積層 | 2021論文
The interview lasted for half a year. Last month, I successfully got Alibaba p7offer. It was all because I chewed the latest interview questions in 2020!