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>
相关推荐
heytoo14 分钟前
同一个模型,为什么结果差10倍?差的不是模型
前端·agent
霪霖笙箫15 分钟前
「JS全栈AI学习」九、Multi-Agent 系统设计:架构与编排
前端·面试·全栈
慕斯fuafua17 分钟前
CSS——定位
前端·css
Cache技术分享17 分钟前
384. Java IO API - Java 文件复制工具:Copy 示例完整解析
前端·后端
shadowcz00719 分钟前
Chrome Skills 来了:把你的 AI 提示词变成一键工具
前端·人工智能·chrome
踩着两条虫19 分钟前
VTJ核心引擎开源项目概览
前端·vue.js·低代码
Front思20 分钟前
解决 uniapp Dart Sass 2.0.0 弃用警告
前端·uni-app·sass
农夫山泉不太甜20 分钟前
CSS 新特性与冷门属性深度剖析
前端
Hy行者勇哥22 分钟前
Chrome 浏览器如何“网页长截图”和“网站打包成应用”
前端·chrome
threelab26 分钟前
Vue3 + Trilab:打造高扩展性三维可视化插件化框架实战指南
javascript·3d·webgl