Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5键盘收缩监控 #26

Open
hstarorg opened this issue May 5, 2019 · 0 comments
Open

H5键盘收缩监控 #26

hstarorg opened this issue May 5, 2019 · 0 comments

Comments

@hstarorg
Copy link
Owner

hstarorg commented May 5, 2019

// 初版
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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant