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

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

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

实现 : 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
            }
        },
相关推荐
fakaifa2 小时前
八戒农场小程序V2最新源码
小程序·uni-app·php·生活·开源软件
包淼淼2 小时前
微信小程序自定义navigationBar顶部导航栏(背景图片)适配所有机型,使用tdesign-miniprogram t-navbar设置背景图片
微信小程序·小程序·tdesign
2401_844137952 小时前
JAVA同城生活新引擎外卖跑腿团购到店服务多合一高效系统小程序源码
微信·微信小程序·小程序·生活·微信公众平台·微信开放平台
哈尔滨财富通科技3 小时前
财富通公司开发维修售后小程序,解决售后维修问题
大数据·小程序·云计算·售后小程序·哈尔滨小程序
我非夏日3 小时前
小程序开发设计-第一个小程序:注册小程序开发账号②
小程序
骆晨学长3 小时前
基于springboot的智慧社区微信小程序
java·数据库·spring boot·后端·微信小程序·小程序
风等雨归期6 小时前
【python】【绘制小程序】动态爱心绘制
开发语言·python·小程序
李宥小哥7 小时前
微信小程序07-开发进阶
微信小程序·小程序·notepad++
艾小逗8 小时前
uniapp快速入门教程,内容来源于官方文档,仅仅记录快速入门需要了解到的知识点
小程序·uni-app·app·es6
程序员阿龙8 小时前
【2025】儿童疫苗接种预约小程序(源码+文档+解答)
小程序·毕业设计·小程序开发·预约小程序·疫苗管理小程序·出勤数据分析·智能考勤