//獲取滾動條可滾動高度 wx.getSystemInfo({ success: (res) => { let screenHeight = wx.getSystemInfoSync().windowHeight //獲取屏幕高度 // 通過query 獲取其余盒子的高度 let query = wx.createSelectorQuery().in(this) query.select('.bgc').boundingClientRect() query.select('.bgcgray').boundingClientRect() query.select('.container').boundingClientRect() query.select('.foot_submit_bar').boundingClientRect() // 通過query.exec返回的數組 進行減法 同時 去除margin 和border的 query.exec(res => { let bgcHeight = res[0].height let bgcgrayHeight = res[1].height let containerHeight = res[2].height let footHeight = res[3].height screenHeight = screenHeight - bgcHeight - bgcgrayHeight - containerHeight - footHeight - 64 console.log(screenHeight, 'screenHeight') this.setData({ clientHeight: screenHeight }); }) // this.setData({ // clientHeight: res.windowHeight - 108 // }); } });
<view class='r_first_category' style='width:160rpx'>
// 因為scroll-view必須得給定一個高度 這個高度在不同手機下 需要進行動態計算 因為很多盒子是不設置高的 <scroll-view scroll-y style='height:{{clientHeight*2}}rpx;'> <view class="r_item {{itemIndex === index ? 'item_active':'' }}" wx:for="{{category_list}}" wx:key='index' data-id="{{item.category_id}}" data-index="{{index}}" bindtap='navChange'> {{item.short_name =='' ? item.category_name:item.short_name}} </view> <!-- // 補一個虛擬的盒子頂住下處 --> <view style="margin-top:4rpx;" class='no_more'></view> </scroll-view> </view>