最近公司要添加一个新的模块,导航栏和底部“分享给好友”的按钮固定不动。中间的内容就是可滑动的。
用当前页面的JS计算高度
onLoad () {
// 页面加载时就计算scroll-view高度
this.calScrollHeight()
}
// 计算scroll-view高度
calScrollHeight () {
let windowHeight = wx.getSystemInfoSync().windowHeight // 屏幕的高度
let windowWidth = wx.getSystemInfoSync().windowWidth // 屏幕的宽度
this.setData({
scroll-height: windowHeight * 750 / windowWidth - 120(除scroll外的组件高度,我这里是底部分享给好友按钮的高度) - 17(这是我在顶部设置的margin-top,有设置就要减,没有就不用了,视个人情况而定)
})
},
WXML
<scroll-view scroll-y style="height: {{scroll-height}}rpx;" >
</scroll-view>