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>
相关推荐
ClickHouseDB19 分钟前
ClickHouse .NET 驱动程序新特性:从 1.0 到 1.3 的演进之路
java·前端·windows
bitbrowser30 分钟前
Gmail注册要求手机号如何解决?哪些情况可以不填手机号
前端·指纹浏览器·gmail
LCG米31 分钟前
STM32 HardFault故障定位实测:压栈帧寄存器解析、CFSR故障源判读与出错地址回溯
前端·javascript·stm32·单片机·嵌入式
夏幻灵36 分钟前
Express 静态资源托管详解:从本地 HTML 到 express.static()
前端·html·express
yyuuuzz1 小时前
云服务器部署 web 项目的进程常驻记录
运维·服务器·前端·阿里云·云计算·aws
持敬chijing1 小时前
白盒测试与代码审计-JS 数据逆向
javascript·网络·安全·web安全·网络安全·网络攻击模型·安全威胁分析
IT_陈寒1 小时前
一文搞懂React的核心概念
前端·人工智能·后端
薛一半1 小时前
Redux实战:组件状态管理全解析
开发语言·前端·javascript·react.js
风骏时光牛马2 小时前
功能模块性能测试用例验证
前端