ios和安卓监听软键盘弹出和收起

this.windowHeight = document.documentElement.offsetHeight
    const self = this
    const u = navigator.userAgent
    const isIOS = !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/)
    if (isIOS) {
      window.addEventListener('focusin', function() {
        self.text = '键盘弹出'
      })
      window.addEventListener('focusout', function() {
        self.text = '键盘收起'
      })
    } else {
      window.addEventListener('resize', function() {
        self.thisHeight = document.documentElement.offsetHeight
        if (self.windowHeight - self.thisHeight > 140) {
          self.text = '键盘弹出'
        } else {
          self.text = '键盘收起'
        }
      })
    }
原文地址:https://www.cnblogs.com/wjyz/p/13606771.html