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()方法的专有变体。

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

猜你喜欢

转载自www.cnblogs.com/wangxi01/p/12568381.html