美文网首页
ios手机 input输入框键盘消失后,键盘区域仍存在

ios手机 input输入框键盘消失后,键盘区域仍存在

作者: 遛_遛 | 来源:发表于2018-12-06 10:21 被阅读0次

这个问题会导致页面定位的按钮会失灵,所以当键盘消失后,我们要想办法将页面拉下来,通过监听键盘事件,来解决:

  let keyTimer = null;
  document.body.addEventListener('focusin', () => {
    //软键盘弹起事件
    clearTimeout(keyTimer);
  });
  document.body.addEventListener('focusout', () => {
    // 软键盘关闭事件
    window.scrollTo(0, 0);
    keyTimer = setTimeout(() => {
      if (window.pageYOffset > 0) {
        window.scrollTo(0, 0);
      }
    }, 200);
  });

相关文章

网友评论

      本文标题:ios手机 input输入框键盘消失后,键盘区域仍存在

      本文链接:https://www.haomeiwen.com/subject/sqyncqtx.html