手机网页输入框或者文本域被输入法挡掉解决方法

var focusElem;
//获取页面高度
var clientHeight = document.body.clientHeight;
//设置监听聚焦事件
document.body.addEventListener("focus", function(e) {
    focusElem = document.getElementById('content')
}, true);
//设置监听窗口变化时间
window.addEventListener("resize", function() {
    if(focusElem && document.body.clientHeight < clientHeight) {
        //使用scrollIntoView方法来控制输入框
        focusElem.scrollIntoView(false);
    }
});

猜你喜欢

转载自blog.csdn.net/qq_41373307/article/details/82593010