移动端软键盘挡住输入框

在IOS端不需要加这一段代码,在软键盘出来的时候页面会自动被顶上去,但是Android不会,所以加一些条件判断,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
//处理isAndroid问题
if (isAndroid) {
$(window).on('resize', function (e) {
if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
window.setTimeout(function () {
        document.activeElement.scrollIntoViewIfNeeded();
      }, 0);
   }
   });
}