https://developers.weixin.qq.com/miniprogram/dev/api/wxml/wx.createSelectorQuery.html
const query = wx.createSelectorQuery();
query.select('#navigationBar').boundingClientRect(function (rect) {
debugger;
thisEls.setData({
navBarh: rect.height
})
}).exec();
query.select('.nav').boundingClientRect(function (rect) {
debugger;
thisEls.setData({
navh: rect.height
})
}).exec();
或者
const query = wx.createSelectorQuery();
query.select('#navigationBar').boundingClientRect();
query.select('.nav').boundingClientRect();
query.exec(function (res) {
console.log(2);
debugger;
res[0].top // #the-id节点的上边界坐标
res[1].scrollTop // 显示区域的竖直滚动位置
})
开发工具一切正常,真机一点反应都没
你这个#navigationBar'是自定义navbar组件吧,.nav在#navigationBar下的话
==============
页面js
const query = wx.createSelectorQuery();
query.select('#navigationBar').boundingClientRect(function (rect) {
debugger;
thisEls.setData({
navBarh: rect.height
})
}).exec();
query = wx.createSelectorQuery().in(this.selectComponent('#navigationBar'))
query.select('.nav').boundingClientRect(function (rect) {
debugger;
thisEls.setData({
navh: rect.height
})
}).exec();
要不上代码片段,帮你瞧瞧
onReady: function () {
// 获取头部导航和标题高度
var thisEls = this;
console.log(1);
const query = wx.createSelectorQuery();
query.select('#navigationBar').boundingClientRect();
query.select('.nav').boundingClientRect();
query.exec(function (res) {
console.log(2);
debugger;
res[0].top // #the-id节点的上边界坐标
res[1].scrollTop // 显示区域的竖直滚动位置
})
let thidata = this.data;
var h = wx.getSystemInfoSync().windowHeight // 获取当前窗口的高度
this.setData({
height: (h - thidata.navh - thidata.navBarh) + 'px'
})
},
这样可以,谢啦
const query = this.createSelectorQuery();
query.select('#navigationBar').boundingClientRect();
query.select('.nav').boundingClientRect();
query.exec(function (res) {
thisEls.setData({
navBarh: rect.height
})
})