背景
一个 tab 页面,每个页面的背景色是 #f4f4f4 数据都是动态的,数据会越来越多。当数据没有撑满屏幕的高度时,为了保证最外层的view的背景色是 #f4f4f4 。高度必须是屏幕高度的100%也就是100vh。如果数据撑开屏幕的高度的话,最外层view给高度可以是 auto 或者是 100% 。
实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| let that = this; wx.getSystemInfo({ success: function (res) { let windowHeight = res.windowHeight; let tabsHeight, grounpHeight; console.log(res.windowHeight); let query = wx.createSelectorQuery(); query.select('#order-grounp').boundingClientRect(); query.exec(function (res) { grounpHeight = res[0].height; let query1 = wx.createSelectorQuery(); query1.select('#tabs').boundingClientRect(); query1.exec(function (res) { tabsHeight = res[0].height; console.log('tabsHeight' + tabsHeight); console.log('grounpHeight' + grounpHeight); if ((windowHeight - tabsHeight) > grounpHeight){ that.setData({ _height: '100vh' }) }else{ that.setData({ _height: '100%' }) } }); }); } })
|