1.data中定義兩個變量
// 吸頂
fixTop: 0,//頭部查詢條件的高
scrollTop: 0,
2.onShow中添加方法this.boundingClientRect()
onShow() {
this.boundingClientRect()
},
3.boundingClientRect方法
// 實現菜單吸頂
boundingClientRect() {
let query = wx.createSelectorQuery();
query.select('.list-search').boundingClientRect(res => {
this.setData({
fixTop: res.top,
})
}).exec()
},
//監測頁面滾動
onPageScroll: function (e) {
this.setData({
scrollTop: e.scrollTop
});
},