web app ,输入框被Android 键盘遮挡

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);
        }
      })
    }

说明:

Element.scrollIntoViewIfNeeded()方法用来将不在浏览器窗口的可见区域内的元素滚动到浏览器窗口的可见区域

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章