小程序中实现手风琴标题吸附顶部

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()
    });
  },

猜你喜欢

转载自blog.csdn.net/web_cgh/article/details/80066419