场景:IOS微信内置浏览器在打开H5页面的时候,input输入时软键盘弹起,页面会被顶起来,软键盘收起的时候页面不回弹
出现的条件为:
页面高度过小&&聚焦时,页面需要往上移动的时候
解决:(以vantUI的输入框为例)给输入框添加一个失去焦点的事件
//解决微信端页面被顶起
temporaryRepair() {
let currentPosition, timer;
let speed = 1; //页面滚动距离
timer = setInterval(function() {
currentPosition =
document.documentElement.scrollTop || document.body.scrollTop;
currentPosition -= speed;
window.scrollTo(0, currentPosition); //页面向上滚动
currentPosition += speed;
window.scrollTo(0, currentPosition); //页面向下滚动
clearInterval(timer);
}, 1);
},
另外其他方法:
<template>
<input type="text" @focus="focus" @blur="blur">
</template>
<script>
export default {
data() {
return {
scrollTop: 0
}
},
methods: {
focus() {
this.scrollTop = document.scrollingElement.scrollTop;
},
blur() {
document.scrollingElement.scrollTo(0, this.scrollTop);
}
}
}
</script>