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' }
