//解决iPhoneX软键盘收起后页面没有正确归位的问题
function isIos () {
let u = navigator.userAgent
return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
}
if (isIos()) {
let isReset;
$('body').focusout(()=>{
isReset = true;
setTimeout(() => {
if (isReset) window.scroll(0, 0);
// document.body.scrollTop = document.body.scrollTop
}, 100);
}).focusin(()=>{
isReset = false;
})
}
该博客介绍了如何针对iPhoneX及类似设备解决页面在软键盘收起后位置不正确的bug。通过检测设备类型并监听body元素的焦点变化,设置定时器在100毫秒后滚动到顶部,从而确保页面正确归位。
6409

被折叠的 条评论
为什么被折叠?



