Android 监听输入框焦点事件无效 需要监听监听resize
mounted() {
if(Utils.iosShell){ //是否是ios
window.addEventListener('focusout', () => {
this.recoverScroll();
})
}else{
const innerHeight = window.innerHeight;
window.addEventListener('resize', () => {
const newInnerHeight = window.innerHeight;
if (innerHeight > newInnerHeight) {
// 键盘弹出事件处理
} else {
// 键盘收起事件处理
this.recoverScroll()
}
});
}
},
methods: {
//- 回复滚动条位置
recoverScroll(){
// 获取滚动的容器高度
const container = document.getElementsByClassName("scroll-container")[0]
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
container.scroll(0, scrollTop)
},
}