小程序页面指定区域局部滚动,做上拉和触底刷新

业务需求:在页面某个固定区域滑动

思路:滑动高度 = 页面高度 - 自定义导航高度(不是自己自定义的导航可以省略)- 按钮高度 - 单词数高度

实现 : 1.数据展示区内使用scroll-view,设置y轴滚动(给固定高度=滑动高度)

2.计算展示区盒子的高度,仅在范围内允许滚动

3.保持页面固定,下拉触底时不能带动页面滚动

javascript 复制代码
  getScrollHeight() {
      const that = this;
      wx.getSystemInfo({
        success: (res) => {
          let systemInfo = wx.getSystemInfoSync();
          //页面高度
          let windowHeight = systemInfo.windowHeight;
          // that.statusBarHeight = systemInfo.statusBarHeight;
          // 胶囊位置信息
          let rect = wx.getMenuButtonBoundingClientRect();
          // that.menuButtonRect = JSON.parse(JSON.stringify(rect));
          let navBarHeight =
            (rect.top - systemInfo.statusBarHeight) * 2 + rect.height;
          // this.navBarHeight = navBarHeight;
          // 自定义导航栏的高度
          let height = systemInfo.statusBarHeight + navBarHeight;

          let query = wx.createSelectorQuery().in(that);
          query.select(".nav-btn").boundingClientRect();
          query.select(".collect-btn").boundingClientRect();
          query.select(".nav-bg").boundingClientRect();
          query.exec((res) => {
            let h1 = res[0].height;
            let h2 = res[1].height;
            let h3 = res[2].height;
            that.navBgHeight = h3;
           

            let scrollHeight = windowHeight - h1 - h2 - height;
            that.scrollHeight = scrollHeight;
          });
        },
      });
    },

        //HTML
        <scroll-view
          scroll-y
          scroll-with-animation
          @scrolltolower="handleScrolltolower"
          class="bs scroll-view"
          :style="{ maxHeight: `${scrollHeight}px` }"
        >
          <view
            style="padding: 0 30rpx 30rpx 30rpx"
            v-if="navList[0].isActivation"
          >
            <collect-list @toTranslate="toTranslate" ref="collectList" />
          </view>
          <sign-list
            @cancelSign="cancelSign"
            v-if="navList[2].isActivation || navList[1].isActivation"
          />
        </scroll-view>

scroll-view的事件。

bindscrolltoupper 触顶事件,放入下拉刷新处理方法

bindscrolltolower 触底事件,放入触底加载处理方法

根据自己的需要添加

触底之后可能会出现父盒子会下拉,导致出现页面空白bug

解决方法==>在pages.json文件夹加上"disableScroll":true 属性

javascript 复制代码
        {
            "path": "pages/tabbar/collect",
            "style": {
                "navigationBarTitleText": "收藏",
                "navigationStyle": "custom",
                "disableScroll":true
            }
        },
相关推荐
云起SAAS3 小时前
ai公司起名取名抖音快手微信小程序看广告流量主开源
微信小程序·小程序·ai编程·看广告变现轻·ai公司起名取名
黑马源码库miui520863 小时前
JAVA购物返利商品比价系统源码支持微信小程序
微信·微信小程序·小程序·1024程序员节
淡淡蓝蓝5 小时前
uni-app小程序往飞书多维表格写入内容(包含图片)
小程序·uni-app·飞书
2501_915921436 小时前
iOS混淆与IPA加固全流程(iOS混淆 IPA加固 Ipa Guard实战)
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者87 小时前
iOS 26 App 开发阶段性能优化 从多工具协作到数据驱动的实战体系
android·ios·小程序·uni-app·iphone·webview·1024程序员节
2501_915106327 小时前
深入剖析 iOS 26 系统流畅度,多工具协同监控与性能优化实践
android·ios·性能优化·小程序·uni-app·cocoa·iphone
游戏开发爱好者810 小时前
iOS 26 App 查看电池寿命技巧,多工具组合实践指南
android·macos·ios·小程序·uni-app·cocoa·iphone
abigale0312 小时前
开发实战 - ego商城 - 补充:小程序性能优化
小程序·uniapp·小程序分包
说私域13 小时前
开源AI智能客服、AI智能名片与S2B2C商城小程序融合下的商家客服能力提升策略研究
人工智能·小程序
游戏开发爱好者818 小时前
iOS 混淆工具链实战 多工具组合完成 IPA 混淆与加固 无源码混淆
android·ios·小程序·https·uni-app·iphone·webview