试过点击、input获得焦点时重新定位滚动条结果不生效,重新找的下面的方法应该比较通用。
//有效解决安卓手机键盘弹出输入框被挡住问题
if (/Android/gi.test(navigator.userAgent)) {//浏览器属性为安卓时生效
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);
}
})
}
window.setTimeout(function () {
document.activeElement.scrollIntoViewIfNeeded();//移动页面使输入框置于可视区域
}, 0);
}
})
}