1?通過uni.createSelectorQuery() 來實現(xiàn),
注意:要獲得的高度,是在頁面上dom已經(jīng)渲染完成之后才能獲得
我使用的是頁面生命周期? onReady()中調(diào)用的

????????????????let _this = this;
????????????????const query = uni.createSelectorQuery()
? ? ? ? ? ? ? ? ?query.select('#tab').boundingClientRect()
? ? ? ? ? ? ? ? ? ?query.selectViewport().scrollOffset()
? ? ? ? ? ? ? ? ? ? query.exec(function(res){
? ? ? ? ? ? ? ? ? ? ? ? debugger
? ? ? ? ? ? ? ? ? ? ? ?// res[0].top? ? ? // #tab節(jié)點的上邊界坐標
? ? ? ? ? ? ? ? ? ? ? ? // res[1].scrollTop // 顯示區(qū)域的豎直滾動位置
? ? ? ? ? ? ? ? ? ? ? ? _this.height=resu.windowHeight-res[0].top +'px'
? ? ? ? ? ? ? ? ? ? ? ? console.log('高度',res[0].height);
? ? ? ? ? ? ? ? ? ? ? ? console.log('demo的元素的信息',res);
? ? ? ? ? ? ? ? ? ? })
我是用于實現(xiàn)頁面滾動后把列表的導航條吸附在頂部,在微信小程中使用有效,在app端使用這個方法不能獲取到距離頂部的高度,只有demo元素的信息