1. 程式人生 > 其它 >微信小程式,滾動標記訊息已讀

微信小程式,滾動標記訊息已讀

記錄。

滾動的時候去找dom,然後看top是否小於某一個高度(螢幕可用高度)為已讀,進行標記。

<scroll-view scroll-y scroll-into-view="{{toItemView}}" bindscroll="scrolltoupper">
<view wx:for="{{10}}"  id="ItemView{{index}}">
</view>   
</scroll-view>

  

// 獲取滾動條當前位置
  scrolltoupper: function (e) {
    let that =this;
    var Lists = this.createSelectorQuery().selectAll(".WaitingTag").boundingClientRect();
    Lists.exec(function (res) {
      res[0].forEach((item,index) => {
        //檢查是否已讀,top在小於螢幕可用範圍內為已讀
        if(item.top<=(that.data.windowHeight-that.data.CustomBar-200))//一個框框最小400rpx
        {
          if(that.data.readList.indexOf(item.id)<0){
            that.data.readList.push(item.id);
            var list=that.data.readList;
            that.setData({
              readList:list
            })
        //設定已讀操作。。。
         } } }); }) },