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();
要不上代码片段,帮你瞧瞧