在iOS中,输入框弹起键盘前后,页面都可能出现问题,需要监听下键盘弹起收起的状态,然后自己滚动一下。
// 监听键盘收起及弹出状态
document.body.addEventListener('focusout', () => {
if (isIphone()) {
setTimeout(() => {
document.body.scrollTop = document.body.scrollHeight
}, 100)
}
})
document.body.addEventListener('focusin', () => {
if (isIphone()) {
setTimeout(() => {
document.body.scrollTop = document.body.scrollHeight
}, 100)
}
})
你也可以参考一下IOS下input获取焦点,弹出软键盘导致页面内容被顶上去。