移动端为什么会有 300ms 点击延迟,如何解决?
参考答案
原因
早期移动浏览器为区分"单击"与"双击缩放",在 touchend 后等待约 300ms 判断是否有第二次点击,导致 click 延迟。
解决
<meta name="viewport" content="width=device-width, initial-scale=1">:现代浏览器在该配置下已取消延迟;- CSS:
touch-action: manipulation(禁止双击缩放,去掉延迟); - 用
touchend自行处理点击(注意 preventDefault 会阻断滚动/长按); - FastClick 库(历史方案,绑定 touchend 后立即派发 click);
- 使用 Pointer Events。
现代项目基本只需 viewport 配置 + touch-action,无需 FastClick。