處理移動(dòng)端 click
事件 300 毫秒延遲斜棚, 由 FT Labs 開發(fā)仪或,Github 項(xiàng)目地址:https://github.com/ftlabs/fastclick 。
為什么存在延遲窗市?
According to Google
:
...mobile browsers will wait approximately 300ms from the time that you tap the button to fire the click event. The reason for this is that the browser is waiting to see if you are actually performing a double tap.
從點(diǎn)擊屏幕上的元素到觸發(fā)元素的 click
事件栗菜,移動(dòng)瀏覽器會(huì)有大約 300 毫秒的等待時(shí)間林束。為什么這么設(shè)計(jì)呢? 因?yàn)樗肟纯茨闶遣皇且M(jìn)行雙擊(double tap)操作稽亏。
使用方法
具體的使用方法有很多種壶冒,在這里只列舉一種。具體參考 https://github.com/ftlabs/fastclick截歉。
使用 npm 安裝:
npm install fastclick --save
import FastClick from 'fastclick'
FastClick.attach(document.body)
不使用 FastClick 的場景
- 桌面瀏覽器
- 如果
viewport meta
標(biāo)簽中設(shè)置了 width=device-width胖腾, Android 上的 Chrome 32+ 會(huì)禁用 300ms 延時(shí),所以也無需使用本插件
<meta name="viewport" content="width=device-width, initial-scale=1">
-
viewport meta
標(biāo)簽如果設(shè)置了user-scalable=no
瘪松,Android 上的 Chrome(所有版本)都會(huì)禁用 300ms 延遲咸作,但是這樣就無法讓用戶多點(diǎn)觸控縮放網(wǎng)頁了