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.οnresize=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/);
}
来源:CSDN
作者:栖息
链接:https://blog.csdn.net/Magneto7/article/details/86085835