Ios移动端fastClick导致 input触控不灵敏的解决办法!

FastClick
移动设备上的浏览器默认会在用户点击屏幕大约延迟300毫秒后才会触发点击事件,这是为了检查用户是否在做双击。为了能够立即响应用户的点击事件,就有了FastClick

安装完发现输入框点击变得不灵敏,第二次点击页面中的输入框需要长按一会才能正常唤起键盘输入。(安卓是正常的)

我用的是vue3 这里直接再main.js修改即可!
解决方案

// 引入
import fastClick from 'fastclick'
fastClick.attach(document.body)
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()
  }
}
ios 软键盘关闭后 页面不会回弹(解决IOS中input失焦后,页面上移,点击不了问题)
解决方法:
const u = navigator.userAgent
let flag
let myFunction
const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
if (isIOS) {
    
    
  document.body.addEventListener('focusin', () => {
    
     // 软键盘弹起事件
    flag = true
    clearTimeout(myFunction)
  })
  document.body.addEventListener('focusout', () => {
    
     // 软键盘关闭事件
    flag = false
    if (!flag) {
    
    
      myFunction = setTimeout(function () {
    
    
        window.scrollTo({
    
     top: 0, left: 0, behavior: 'smooth' })// 重点  =======当键盘收起的时候让页面回到原始位置(这里的top可以根据你们个人的需求改变,并不一定要回到页面顶部)
      }, 200)
    }
  })
}

最后再在全局文件添加以下样式

  -moz-user-select: none; //css 让文字不被选中

  -webkit-user-select: none; //禁止移动端用户用鼠标在页面上选中文字

  user-select: none; //禁止用户用鼠标在页面上选中文字
`

猜你喜欢

转载自blog.csdn.net/weixin_46533797/article/details/126517798