微信小程序监听页面滚动的事件

有些用户的需求是,上下滑动屏幕要求隐藏掉某些显示区域。或者滑动到指定位置时显示某些内容。
可做监听事件四个:
一、JS自带的:

//开始滚动
  onPageScroll (e) { 
  console.log('滚起来')
  },

这个监听的不够灵敏,BUg较多。
二 、手势事件

<view class="wrapIndex" bindtouchstart="touchStart" bindtouchend="touchEnd"></view>
touchStart(e){
    //console.log('滚起来', e);
    this.setData({
      scrollStop: false
    })
  },
  touchEnd(e){
   // console.log('停下来', e);
    this.setData({
      scrollStop: true
    })
  },

这个较为灵敏好用。但是不能随心所欲。至少可一在整个屏幕内进行操作。
三、scroll-view组件
四、scroll-into-view属性。
三四可以参考scroll-view组件:
https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html

发布了209 篇原创文章 · 获赞 38 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/weixin_43953710/article/details/104039610