在vue里添加了fastclick来处理移动端点击延迟的问题,但是在mac上使用的时候,发现click事件需要点击2下才能触发点击事件。
import fastclick from 'fastclick';
const { userAgent } = navigator;
const deviceIsIOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
export const fastFunc = () => {
/* eslint-disable */
fastclick.attach(document.body);
fastclick.prototype.needsClick = (target) => {
switch (target.nodeName.toLowerCase()) {
// Don't send a synthetic click to disabled inputs (issue #62)
case 'button':
case 'select':
case 'textarea':
if (!target.disabled) {
return true;
}
break;
case 'input':
// File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
if ((deviceIsIOS && target.type === 'file') || !target.disabled) {
return true;
}
break;
case 'label':
case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
case 'video':
return true;
// **************************************************
// 添加的click事件的过滤对象
// 这里写上 你要 不阻止冒泡的元素名就可以了
// **************************************************
case 'div':
case 'img':
case 'p':
case 'span':
case 'a':
case 'i':
return true;
}
};
};
/* eslint-enable */
export default { fastFunc };
写完这个,最好不要用 touchstart 和 touchend 了,因为这样滑动也会触发这两个事件