IOS系统输入键盘弹出后没有复位的问题

背景

iOS系统中,大部分移动端输入法弹出后,会导致页面没有复位,或者复位后的点击事件错位的问题,可参考以下代码解决

setTimeout(function () {
  const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
  window.scrollTo(0, Math.max(scrollHeight - 1, 0));
}, 200)

eg:

// vue
<input @blur="handleBlur" class="form__input" placeholder="电话" v-model="form.phone" type="number">

// js
handleBlur() {
  setTimeout(function () {
    const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
    window.scrollTo(0, Math.max(scrollHeight - 1, 0));
  }, 200)
}

posted @ 2022-02-16 10:10  StartNigth  阅读(86)  评论(0)    收藏  举报