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

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

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

实现 : 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
            }
        },
相关推荐
小小王app小程序开发8 小时前
淘宝扭蛋机小程序核心玩法拆解与技术运营分析
大数据·小程序
说私域10 小时前
AI智能名片商城小程序数据清洗的持续运营策略与实践研究
大数据·人工智能·小程序·流量运营·私域运营
东东51611 小时前
xxx食堂移动预约点餐系统 (springboot+微信小程序)
spring boot·微信小程序·小程序·毕业设计·个人开发·毕设
CHU72903512 小时前
一番赏盲盒抽卡机小程序:解锁惊喜体验与社交乐趣的多元功能设计
前端·小程序·php
2501_9159184113 小时前
HTTPS 代理失效,启用双向认证(mTLS)的 iOS 应用网络怎么抓包调试
android·网络·ios·小程序·https·uni-app·iphone
数字游民952714 小时前
半年时间大概上了70个web站和小程序,累计提示词超过20w
人工智能·ai·小程序·vibecoding·数字游民9527
说私域14 小时前
微商企业未来迭代的核心方向与多元探索——以链动2+1模式AI智能名片商城小程序为核心支撑
大数据·人工智能·小程序·流量运营·私域运营
276695829215 小时前
美团 小程序 mtgsig
python·小程序·node·js·mtgsig1.2·美团小程序·大众点评小程序
2501_9151063216 小时前
混合应用(Hybrid)安全加固,不依赖源码对成品 IPA 混淆
android·安全·小程序·https·uni-app·iphone·webview
00后程序员张17 小时前
无需越狱,来对 iOS 设备进行调试、管理与分析
android·ios·小程序·https·uni-app·iphone·webview