项目地址:github.com/ftlabs/fast… 膜拜大神
npm
npm install fastclick
JS写法
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
ES6
var FastClick = require('fastclick');
FastClick.attach(document.body);
不使用
如果页面上有一些特定的元素不需要使用fastclick来立刻触发点击事件,可以在元素的class上添加needsclick:
<a class="needsclick">Ignored by FastClick</a>
1.FastClick是不会对PC浏览器添加监听事件
2.Android版Chrome 32+浏览器,如果设置viewport meta的值为width=device-width,这种情况下浏览器会马上出发点击事件,不会延迟300毫秒。
3、所有版本的Android Chrome浏览器,如果设置viewport meta的值有user-scalable=no,浏览器也是会马上出发点击事件。
4、IE11+浏览器设置了css的属性touch-action: manipulation,它会在某些标签(a,button等)禁止双击事件,IE10的为-ms-touch-action: manipulation
<meta name="viewport" content="width=device-width, initial-scale=1">