uniapp实战 —— 自适配高度的可滚动区域(scroll-view的使用技巧)

在这里插入图片描述
自定义的顶部导航栏,可参考博文
https://blog.csdn.net/weixin_41192489/article/details/134852124

如图可见,在页面滚动过程中,顶部导航栏和底栏未动,仅中间的内容区域可滚动。

  • 整个页面的高度设置为 100%,并采用 flex 布局
  • 滚动区域的高度,通过flex布局的flex-grow实现自适配
<template>
  <!-- 顶部--自定义的导航栏 -->
  <CustomNavbar />
  <!-- 中间--自适配高度的滚动区 -->
  <scroll-view scroll-y class="contentBox">
  <!-- 此处省略了页面内容的相关代码 -->
  </scroll-view>
</template>
<style lang="scss">
page {
     
  background-color: #f7f7f7;
  // 总容器高度撑满屏幕
  height: 100%;
  // 使容器内元素使用flex布局
  display: flex;
  flex-direction: column;
}
.contentBox {
     
  // 滚动区自适配高度
  flex-grow: 1;
}
</style>
  • 注意事项:此处样式不能加 scoped

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-08 06:12:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-08 06:12:05       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-08 06:12:05       82 阅读
  4. Python语言-面向对象

    2023-12-08 06:12:05       91 阅读

热门阅读

  1. 鸿蒙(HarmonyOS)应用开发——容器组件(Tabs组件)

    2023-12-08 06:12:05       61 阅读
  2. FFmpeg开发笔记(六)如何访问Github下载FFmpeg源码

    2023-12-08 06:12:05       58 阅读
  3. C#:内存分配

    2023-12-08 06:12:05       46 阅读
  4. 关于Go语言的底层,Slice,map

    2023-12-08 06:12:05       54 阅读
  5. hbase

    hbase

    2023-12-08 06:12:05      39 阅读
  6. 华纳云:宝塔面板下配置Discuz伪静态的步骤

    2023-12-08 06:12:05       57 阅读
  7. debian11,debian 如何删除虚拟内存,交换分区

    2023-12-08 06:12:05       62 阅读