监听键盘弹起与隐藏

window.onresize = () => {
      return (() => {
        //键盘弹起与隐藏都会引起窗口的高度发生变化
        const resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;

        if (resizeHeight - 0 < originalHeight - 0) {
          //当软键盘弹起,在此处操作
          console.log('进入到软键盘弹起=========');
          document.querySelector('body').setAttribute('style', 'height:' + originalHeight + 'px;');
          this.scrollerHeight = resizeHeight;
        } else {
          //当软键盘收起,在此处操作

          document.querySelector('body').setAttribute('style', 'height:100%;');
          this.scrollerHeight = '100%';
        }
      })();
    };
posted @ 2021-07-30 10:10  握梅又闻花  阅读(105)  评论(0)    收藏  举报