需求:頁面滾動到底部時,隱藏浮標隱藏
- 主要代碼
const height = wx.getSystemInfoSync().windowHeight
const query = wx.createSelectorQuery().in(this)
query.select('#list').boundingClientRect()
query.selectViewport().scrollOffset()
query.exec((res: any) => {
// 列表的bottom不會為0
// 當列表觸底時,有一個窗口的高度的內容處於頁面內,所以當列表的bottom等於窗口高度時,列表到達底部
if (res[0].bottom == height) {
// 頁面到達底部,此時可以根據需要進行隱藏浮標
}
})