修复苹果iOS 原生键盘遮挡fixed区的input输入框

// css
.mainBox{
    height:100vh;
    position:relative;
}
.inputBox{
    position:absolute;
    bottom:0;
}
// 输入框得到焦点事件
onFocus() {
    setTimeout(function(){
        // 设置body的高度为可视高度+302
        // 302为原生键盘的高度
        document.getElementsByTagName('body')[0].style.height = (window.innerHeight + 302) + 'px';
        document.body.scrollTop = 302;
    }, 300)
}
// 输入框失去焦点事件
onBlur() {
    // 设置body恢复原来的高度
    document.getElementsByTagName('body')[0].style.height = window.innerHeight + 'px';
}
相关文章
相关标签/搜索