vue.js 使用 fastclick解决移动端click事件300毫秒延迟方法
生活随笔
收集整理的這篇文章主要介紹了
vue.js 使用 fastclick解决移动端click事件300毫秒延迟方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一般情況下一些框架就自動解決了這個問題
?
一.使用npm安裝:
npm install fastclick -S
二.用法:
安裝完以后,可以在在main.js中全局引入,并綁定到body,全局生效。或者在單頁面引入,只針對當前頁面生效
//引入 import FastClick from 'fastclick' //初始化FastClick實例。在頁面的DOM文檔加載完成后 FastClick.attach(document.body)
三.使用過程中存在的bug:
當使用FastClick 時,input框在ios上點擊輸入調取手機自帶輸入鍵盤不靈敏,有時候甚至點不出來。而安卓上完全沒問題。這個原因是因為FastClick的點擊穿透。解決方法:
// 添加Fastclick移除移動端點擊延遲 import FastClick from 'fastclick' //FastClick的ios點擊穿透解決方案 FastClick.prototype.focus = function (targetElement) {let length;if (targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {length = targetElement.value.length;targetElement.focus();targetElement.setSelectionRange(length, length);} else {targetElement.focus();} };FastClick.attach(document.body)
?
總結
以上是生活随笔為你收集整理的vue.js 使用 fastclick解决移动端click事件300毫秒延迟方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《乐高EV3机器人搭建与编程》——1.6
- 下一篇: 快递柜APP开发需要注意的地方