小程序监听页面滚动开始和滚动结束

具体思路:

使用页面:onPageScroll 函数

2020-06-10_084653.png

文档地址:https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html

code

暂时用了个定时器来判断滚动是否结束,能够达到效果

onPageScroll(e){
  this.setState({
    scrollTop:e.scrollTop,
    scrollIng:true
  })
 let timer= setTimeout(()=>{
    if(this.state.scrollTop===e.scrollTop){
      this.setState({
        scrollTop:e.scrollTop,
        scrollIng:false
      })
      console.log('滚动结束')
      clearTimeout(timer)
    }
  },300)
}
posted @ 2020-06-10 08:56  Homegu  阅读(2057)  评论(0编辑  收藏  举报