uniapp自定义导航头,页面内容自动盛满禁止滚动效果

1.pages.jso设置自定义头部 "navigationStyle": "custom"

复制代码
{
			"path" : "pages/a/a",
			"style" : 
			{
				"navigationBarTitleText" : "自定义头",
				"navigationStyle": "custom"
			}
		},

2.效果 源码

复制代码
<template>
  <view class="container">
    <view class="custom-navbar" :style="{ height: navBarHeight + 'px' }">
      <view class="title" :style="{ top: titleTop + 'px', height: titleHeight + 'px' }">
        123
      </view>
    </view>

    <view class="content">
      <text>asasa</text>
    </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      navBarHeight: 0,  
      titleTop: 0,  
      titleHeight: 0 
    };
  },
  onLoad() {
    this.calculateNavBarHeight();
  },
  methods: {
    calculateNavBarHeight() {
      const systemInfo = uni.getSystemInfoSync();
      const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
      this.navBarHeight = menuButtonInfo.bottom + (menuButtonInfo.top - systemInfo.statusBarHeight);

      this.titleTop = menuButtonInfo.top;

      this.titleHeight = menuButtonInfo.height;
    }
  }
};
</script>
<style>
  .container {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }

  .custom-navbar {
    background-color: red;
    position: relative; 
  }

  .title {
    position: absolute;
    left: 50%;  
    transform: translateX(-50%); 
    color: white;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .content {
    flex: 1;  
    background-color: green;
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>
相关推荐
半句唐诗39 分钟前
我是如何通过 Access Token 成功发布第一个 npm 包的
前端·npm·node.js
程序员黑豆42 分钟前
鸿蒙应用开发:@Provider 与 @Consumer 跨组件双向同步详解
前端·harmonyos
paopaokaka_luck1 小时前
基于springboot3+vue3的智能文库平台(AI智能搜索、AI智能汇总、实时在线状态展示、多格式文档预览与富文本编辑、Echarts图形化分析)
前端·网络·spring boot·网络协议·echarts
牧艺1 小时前
cos-design PhotoAlbum:用 CSS 3D 做一个「能翻页」的实体相册
前端·css·交互设计
洪贺1 小时前
从原始采样到可缩放心电图:用 h5ECG 绘制自己的 ECG
前端
冰心孤城1 小时前
Excel: xls与xlsx格式转换排坑指南
java·前端·excel
程序员黑豆2 小时前
鸿蒙应用开发之跨组件传参:@Provide 与 @Consume 跨层级数据同步详解
前端·harmonyos
0_Error_2 小时前
猫国建设者 修改资源 自动采集
javascript
贩卖黄昏的熊2 小时前
NestJS简明教程——异常处理和日志
javascript·node.js·nest.js
C++、Java和Python的菜鸟3 小时前
第9章 后端Web进阶(AOP)
java·开发语言·前端