onPageScroll: function (e) { //滚动事件
var that = this, hasMark = false;
that.data.storeGroups.forEach(function (value, index, array) {
console.log(value, array.length)
let query = wx.createSelectorQuery().in(that)
query.select('#theId' + (array.length - 1 - index)).boundingClientRect((res) => {
if (res && res.top < 44 && hasMark === false) {
console.log('res: ', res)
hasMark = true;
that.setData({
title: array[res.dataset.listid].groupName
})
return;
}
if (index === 0 && res.id === 'theId0') {
console.info('index===' + index);
that.setData({
title: ''
})
}
}).exec()
});
},
var that = this, hasMark = false;
that.data.storeGroups.forEach(function (value, index, array) {
console.log(value, array.length)
let query = wx.createSelectorQuery().in(that)
query.select('#theId' + (array.length - 1 - index)).boundingClientRect((res) => {
if (res && res.top < 44 && hasMark === false) {
console.log('res: ', res)
hasMark = true;
that.setData({
title: array[res.dataset.listid].groupName
})
return;
}
if (index === 0 && res.id === 'theId0') {
console.info('index===' + index);
that.setData({
title: ''
})
}
}).exec()
});
},
本文介绍了一种在页面滚动过程中动态更新标题栏的方法。通过监听页面滚动事件并结合选择器查询API,实现随滚动位置变化自动更新顶部导航栏标题的功能。
5609

被折叠的 条评论
为什么被折叠?



