uniapp H5页面安卓输入时软键盘 顶小背景图片高度
1.为最外层容器content设置固定高度 height: 100vh
.content {
width: 100vw;
height: 100vh;
background-image: url(/static/image/bg.png);
background-position: center center;
background-repeat: no-repeat;
background-attachment: scroll;
background-size: 100% 100%;
position: relative;
overflow: hidden;
}
2.onReady中获取content容器高度并保存
onReady(){
let that = this
const query = uni.createSelectorQuery().in(this);
query.select('.content').boundingClientRect(({ height }) => {
that.screenHeight = height
console.log('content的高度是:' + height + 'px');
}).exec();
},
3.为最外层容器content添加获取到的屏幕高度 :style=“screenHeight == 0 ? ‘’:‘height:’+ screenHeight + ‘px;’”
<view class="content" :style="screenHeight == 0 ? '':'height:'+ screenHeight + 'px;'">
这样页面高度就不会改变啦