HstarDoc icon indicating copy to clipboard operation
HstarDoc copied to clipboard

H5键盘收缩监控

Open hstarorg opened this issue 6 years ago • 0 comments

// 初版
export const keyboardUtil = {
  isIphone() {
    return false;
  },
  init() {
    const originalHeight = document.documentElement.clientHeight || document.body.clientHeight;
    window.onresize = function resize() {
      // 键盘弹起与隐藏都会引起窗口的高度发生变化
      const resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
      if (resizeHeight < originalHeight) {
        alert('展开');
      } else {
        alert('收起');
      }
    };

    document.body.addEventListener('focusin', () => {
      // 软键盘弹出的事件处理
      if (this.isIphone()) {
        alert('展开');
      }
    });
    document.body.addEventListener('focusout', () => {
      // 软键盘收起的事件处理
      if (this.isIphone()) {
        alert('收起');
      }
    });
  }
};

keyboardUtil.init();

hstarorg avatar May 05 '19 01:05 hstarorg