修復蘋果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';
}
相關文章
相關標籤/搜索