ios 软键盘弹出, 页面整体上移问题
问题描述对于 ios 系统,输入框输入内容,软键盘弹出,页面内容整体上移,但是软键盘收起,页面内容不会自动回到原本的位置,必须手动下拉才会恢复解决办法handleBlur(){let u = navigator.userAgent;let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);if (isIOS) {setTimeout(() =&g
·
问题描述
对于 ios 系统,输入框输入内容,软键盘弹出,页面内容整体上移,但是软键盘收起,页面内容不会自动回到原本的位置,必须手动下拉才会恢复
解决办法
compatibility(){
let isReset = true;
const u = navigator.userAgent;
const isAndroid = us.indexOf('Android') > -1 || us.indexOf('Adr') > -1;
let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
let originalHeight = document.documentElement.clientHeight || document.body.clientHeight;
if(isAndroid) {
window.onresize = function(){
let resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
if(resizeHeight < originalHeight){
isReset = false;
}else{
isReset = true;
setTimeout(() => {
if(isReset){
window.scroll(0,0)
}
},300)
}
}
}else if(isIOS){
document.body.addEventListener('focusin', () => {
isReset = false;
})
document.body.addEventListener('focusout', () => {
isReset = true;
setTimeout(() => {
if(isReset){
window.scroll(0,0)
}
},300)
})
}
}
componentDidMount(){
this.compatibility()
}
更多推荐
已为社区贡献1条内容
所有评论(0)