fastclick使用方法

为何存在延迟?

从点击屏幕上的元素到触发元素的 click 事件,移动浏览器会有大约 300 毫秒的等待时间。为何这么设计呢? 由于它想看看你是否是要进行双击(double tap)操做。javascript

兼容性

  • Mobile Safari on iOS 3 and upwards
  • Chrome on iOS 5 and upwards
  • Chrome on Android (ICS)
  • Opera Mobile 11.5 and upwards
  • Android Browser since Android 2
  • PlayBook OS 1 and upwards

不该用 FastClick 的场景

  • 桌面浏览器;
  • 若是 viewport meta 标签 中设置了 width=device-width, Android 上的 Chrome 32+ 会禁用 300ms 延时;
 Copy
<meta name="viewport" content="width=device-width, initial-scale=1"> 
  • viewport meta 标签若是设置了 user-scalable=no,Android 上的 Chrome(全部版本)都会禁用 300ms 延迟。
  • IE10 中,能够使用 css 属性 -ms-touch-action: none 禁止元素双击缩放

使用方法

TODO: 修改使用接口css

window.addEventListener('load', function() { FastClick.attach(document.body); }, false); 

Zepto.js:java

$(function() { FastClick.attach(document.body); }); 
相关文章
相关标签/搜索