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>
相关推荐
李溪白几秒前
深入 JavaScript 作用域:从变量提升到执行上下文的底层逻辑
前端
想风4 分钟前
Claude Code 实用技巧工作坊 —— Boris Cherny
前端·后端·github
梦想blog6 分钟前
Claude Code + Chrome MCP:让浏览器自动化测试更简单
前端·chrome·自动化·mcp
YHHLAI6 分钟前
React `useState` 深入浅出
前端·javascript·react.js
夜猫子小强9 分钟前
手搓一个「本地邮件摘要」工具:零依赖、数据不出电脑
前端
PBitW11 分钟前
Element plus 自定义列顺序 —— 求指点
前端·element
绿岛之北11 分钟前
Electron 安全第五章:网络请求安全
前端·electron
深漂的华哥12 分钟前
Ruoyi-Vue-Plus(V5.6.2) 开发环境搭建
java·前端·spring boot·后端·spring·ruoyi
YIAN16 分钟前
TS 面试必考题:type 与 interface 的 6 大核心区别,90% 的人答不全
前端·typescript
Canace17 分钟前
Fable 像素游戏复盘,Vibe Coding 的 10 条工程规则与赛车 Demo 实践
前端·人工智能·游戏开发