// 解决键盘弹出后挡表单的问题 

// 解决键盘弹出后挡表单的问题
    window.addEventListener('resize', function() {
      if(
        document.activeElement.tagName === 'INPUT' ||
        document.activeElement.tagName === 'TEXTAREA'
      ) {
        window.setTimeout(function() {
          if('scrollIntoView' in document.activeElement) {
            document.activeElement.scrollIntoView();
          } else {
            document.activeElement.scrollIntoViewIfNeeded();
          }
        }, 0);
      }
    });

  document.activeElement 的支持程度,发现四大浏览器safari除外, ie firefoxopera都提供了这个对象的支持。但是有点需要注意的,上面的例子中 opera 会把图片作为 可以 focus的对象。导致document.activeElement的结果不一致...

 

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2021-10-02
  • 2022-01-01
  • 2022-12-23
  • 2021-12-19
  • 2021-11-19
  • 2021-05-24
猜你喜欢
  • 2022-01-09
  • 2021-06-29
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案