WeChat applet implements rollback to top function

WeChat applet implements page rollback to the top

I recently encountered a requirement that the calendar needs to be displayed at the top, and then set a floating button to show and hide the calendar. Then, below, a ceiling style was referenced, and then I found that when I want to expand the calendar in the middle of the list, the suction The title of the top will have a little impact, so I thought of clicking to expand the calendar to judge whether the current page is at the top, if not, scroll back to the top and expand the calendar.

js file

// 日历组件点击显示和隐藏
  transmit() {
    
    
    if (this.data.onCalendar == false) {
    
    
      this.setData({
    
    
        onCalendar: true
      })
   // 页面回滚判断
      if(wx.pageScrollTo){
    
    
        wx.pageScrollTo({
    
    
          scrollTop: 0,
        })
      }
    } else {
    
    
      this.setData({
    
    
        onCalendar: false
      })
    }
  },

Here is the method of clicking the button, and then WeChat has its own interface, as long as you call it wx.pageScrollTo, scrollTop: 0you can scroll back to the top.

Guess you like

Origin blog.csdn.net/yh0016/article/details/109492857