1. 程式人生 > >web app ,輸入框被Android 鍵盤遮擋

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()方法用來將不在瀏覽器視窗的可見區域內的元素滾動到瀏覽器視窗的可見區域