效果:
基础库版本:
代码:
wxml
<view class="container">
<view class="f">
<view class="s" style="height: {{windowH/2}}px;"></view>
</view>
</view>
wxss
.container {
width: 100vw;
height: 100vh;
}
.f {
width: 90vw;
height: 50vh;
background-color: lightpink;
margin: 0 auto;
}
.s{
width: 90%;
background-color: lightblue;
margin: 0 auto;
}
js
Page({
data: {
windowH: 0,
},
onLoad() {
wx.getSystemInfo({
success: res => {
this.setData({
windowH: res.windowHeight
})
}
})
},
})