H5虚拟键盘挡住输入框怎么办

2020-07-26 18:18:26
这次给大家带来H5虚拟键盘挡住输入框怎么办,H5虚拟键盘挡住输入框的注意事项有哪些,下面就是实战案例,一起来看一下。

话不多说,请看代码:

//防止键盘把当前输入框给挡住$$('input[type="text"],textarea').on('click', function () {  var target = this;  setTimeout(function(){        target.scrollIntoViewIfNeeded();   },100);});

部分安卓机型适用。

if(/Android [4-6]/.test(navigator.appVersion)) {    window.addEventListener("resize", function() {        if(document.activeElement.tagName=="INPUT" || document.activeElement.tagName=="TEXTAREA") {            window.setTimeout(function() {document.activeElement.scrollIntoViewIfNeeded();            },0);        }    })}

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

H5的存储方式详解

zepto实现移动端无缝向上下滚动