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

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