- 😄 I’m sunha1yang
- 🤔 I’m a Front end developer
- 🔭 I’m currently working on Bytedance
- 🌱 I’m currently learning serverless
blog's Introduction
blog's People
blog's Issues
点击穿透解决方案
移动页面点击穿透问题解决方案
移动端点击穿透现象:
- 点击穿透问题:点击遮罩层mask上的关闭按钮,蒙层消失后发现触发了按钮下面元素的click事件。
- 跨页面点击穿透问题:如果按钮下面恰好是一个有href属性的a标签,那么页面就会发生跳转。
- 跨页面点击穿透问题:直接点击页内按钮跳转至新页,然后发现新页面中对应位置元素的click事件被触发
触发的原因
:js控制页面跳转的逻辑如果是绑定在touch事件上的,而且新页面中对应位置的元素绑定的是click事件,而且页面在300ms内完成了跳转就会触发此现象。
解决办法:
- 只用touch
- 只用click
- 副作用:因为会带来300ms延迟,页面内任何一个自定义交互都将增加300毫秒延迟
- tap后延迟350ms再隐藏mask
- pointer-events
- 实现方式:mask隐藏后,给按钮下面元素添上pointer-events: none;样式,让click穿过去,350ms后去掉这个样式,恢复响应
- 副作用:mask消失后的的350ms内,按钮下面的元素点着击没反应
- 引入fastclick
- 副作用:引入额外的库,多加载几kb资源
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.