在iOS設備下,h5的input框失焦后頁面被頂起來一部分bug 用css解決辦法


body,html{-webkit-overflow-scrolling:touch;}   //針對ios設備 虛擬鍵盤上頂 留白問題 可用css樣式解決

// 收起鍵盤事件
document.body.addEventListener('focusout', function (evt) {
    document.body.scrollTop = 0;
    //軟鍵盤收起的事件處理
    setTimeout(function () {
        document.body.scrollTop = 0;
    }, 1500)
});
//第二種針對安卓虛擬鍵盤
//首先獲取手機屏幕高度
//當屏幕高度發生改變時  讓body高度等於獲取手機屏幕高度

let Height = $('body').height();
    $(window).resize(function() {
        $('body').height(Height);
    });


var Height = document.querySelectorAll('body')[0];
window.addEventListener('resize', fun, false);
function fun(){
  document.querySelectorAll('body')[0].height = Height + 'px'  
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM