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>
相关推荐
会飞的战斗鸡19 分钟前
前端对接生成式AI接口(类ChatGPT)问题汇总
前端·javascript·vue.js·chatgpt·状态模式
还是鼠鼠23 分钟前
Node.js 包管理配置文件详解:package.json、npmrc、package-lock.json 全面解析
前端·javascript·vscode·node.js·json
Danta24 分钟前
面试题大杂烩😘😘
前端·javascript·面试
冲冲冲的小怪兽31 分钟前
书接上回,使用grid来实现自动占据剩余高度布局
前端
GDAL32 分钟前
Node.js 定时任务详解:从基础到高级调度策略
javascript·交互
Front_Yue1 小时前
使用Three.js渲染器创建炫酷3D场景
javascript·3d·three.js
fridayCodeFly1 小时前
<el-form >ref数据监测不到的原因
javascript·vue.js·elementui
沉默璇年1 小时前
使用 pnpm 安装依赖包后,如果将依赖包直接复制内网环境中,可能会出现无法使用的情况,且不能联网下载,如何解决?
前端
数字供应链安全产品选型1 小时前
SBOM风险预警 | 恶意NPM组件开展木马投毒攻击,目标针对国内泛互企业
前端·npm·node.js
web135956097051 小时前
【JavaEE】Spring Web MVC
前端·spring·java-ee