支付宝小程序滚动监听吸顶效果

axml部分

<view class=" {{menuFixed ? 'fixed': ''}}" id="affix">菜单栏</view>

axss部分

.fixed{position: fixed; top: 0; }

js部分

Page({
  data: {
    menuFixed:"",
  },
  // 监听页面滚动距离scrollTop
  onPageScroll: function(e) {
    var that = this;
    // 3.当页面滚动距离scrollTop > 菜单栏距离文档顶部的距离时,菜单栏固定定位
    if (e.scrollTop > 500) {
      that.setData({
        menuFixed: true
      })
    } else {
      that.setData({
        menuFixed: false
      })
    }
  },
原文地址:https://www.cnblogs.com/fms-3/p/10180221.html