var index = 0;
if (isIOS()) {
document.body.addEventListener('focusin', (e) => {
//软键盘弹出的事件处理
index = index + 1;
});
document.body.addEventListener('focusout', (e) => {
//软键盘收起的事件处理
window.setTimeout(() => {
index = index + 1;
if (index%2 === 0) {
$(".header-left")[0].scrollIntoViewIfNeeded();
}
}, 100);
});
} else {
var originalHeight=document.documentElement.clientHeight ||document.body.clientHeight;
window.onresize=function(){
//键盘弹起与隐藏都会引起窗口的高度发生变化
var resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
if(resizeHeight-0<originalHeight-0){
window.setTimeout(() => {
document.activeElement.scrollIntoViewIfNeeded();
}, 100);
}else{
//当软键盘收起,在此处操作
window.setTimeout(() => {
$(".header-left")[0].scrollIntoViewIfNeeded();
}, 100);
}
}
}
// 判断是否为ios
function isIOS() {
var u = navigator.userAgent, app = navigator.appVersion;
return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
}
h5 键盘遮住输入框
最新推荐文章于 2024-08-06 23:00:00 发布