小程序頁面自動滾動到最下面

<scroll-view  style='height:{{height}}' scroll-y  scroll-into-view="{{toView}}" >

      <view class="conversation-list p"  style='height:{{height}}'  id="sco"  >

        <view wx:for="{{recordsReal}} "   id="msg-{{index}}">

        </view>

       </view>

</scroll-view>

//開始滾動

   pageScrollToBottom () { 

    let that = this;

    var query = wx.createSelectorQuery();

    query.select('#sco').boundingClientRect(function (rect) {

      that.setData({

        height: rect.width + 'px'

      })

    }).exec();

    that.setData({

        toView:`msg-${that.data.recordsReal.length-1}`

    })

  },

 

//在發送成功時回調 pageScrollToBottom方法 ,

獲取滾動dom的id  ,toView等於當前一條id的位置

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章