ios系统键盘收起时的页面对齐

2021-06-21  本文已影响0人  Rose_yang
     <Field v-model="name" clearable @focus="inputFocus"/>

 mounted () {
    this.ioskeyBoardFix()
  },

 ioskeyBoardFix () { // ios系统键盘收起时的页面对齐
      let _this = this
      document.body.addEventListener('focusout', () => {
        let u = window.navigator.userAgent
        let isIos = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
        if (!isIos) {
          return false
        }
        _this.scrollTimer = setTimeout(() => {
          window.scrollTo({
            top: 0,
            behavior: 'smooth'
          })
        }, 300)
      })
    },
  inputFocus () {
      if (this.scrollTimer) {
        clearTimeout(this.scrollTimer)
        this.scrollTimer = null
      }
    },
上一篇下一篇

猜你喜欢

热点阅读