billfeller.github.io icon indicating copy to clipboard operation
billfeller.github.io copied to clipboard

ios click事件失效解决方法

Open billfeller opened this issue 7 years ago • 0 comments

  1. 添加onclick事件:
  2. 添加样式:.click { cursor: pointer; }
  3. 使用通用库,如使用 FastClick,就不会遇到兼容性问题

原因: iOS 上,屏幕是触碰的,所以页面元素默认会有 touch 一类事件,而不是 click。也就是说,我点击上面的 .overlay 元素时,iOS 上的 Safari 冒泡的是 touch 一类事件,而不是 click。只有两类元素,链接与 input 输入域才有 click 事件,但通过 cursor: pointer 及 onclick= 代码我们又可以给其它元素变得可点击。这是 iPhone 上的 Safari 有别与其它浏览器的地方。

阅读:

  1. Click event delegation on the iPhone
  2. Handling Events
  3. FastClick

billfeller avatar Apr 19 '17 13:04 billfeller