html5手机网页开发,中文输入法下软键盘遮挡输入框

最近一直再找工作,也好久没有更新博客。。。。  

  之前遇到一个问题,就是在手机上点击input框的时候,发现有的时候就是不自动滑动到相应的位置,怎么兼容这个奇葩的手机呢?

  其实这类问题,只要懂他们的原理话,就很容易解决了。

  原理:当你点在foucs上面计算需要滑动的位置

  解决方式:

// Android 手机下, input 或 textarea 元素聚焦时, 主动滚一把
if (/Android/gi.test(navigator.userAgent)) {
    window.addEventListener('resize', function () {
      if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {
          window.setTimeout(function () {
         document.activeElement.scrollIntoViewIfNeeded(); },
0); } }) }
原文地址:https://www.cnblogs.com/wuxibolgs329/p/6425690.html