android手机的微信H5弹出的软键盘挡住了文本框,如何解决?

window.addEventListener("resize", function () {
       if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
           window.setTimeout(function () {
               document.activeElement.scrollIntoViewIfNeeded();
           }, 0);
       }
   })

Element.scrollIntoViewIfNeeded()方法用来将不在浏览器窗口的可见区域内的元素滚动到浏览器窗口的可见区域。 如果该元素已经在浏览器窗口的可见区域内,则不会发生滚动。 此方法是标准的Element.scrollIntoView()方法的专有变体。

不过这个方法现在是不标准的,最好不要使用

posted @ 2020-03-25 18:16  来亦何哀  阅读(539)  评论(0编辑  收藏  举报