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>
相关推荐
拾年27511 小时前
React Hooks 进阶篇:useMemo / useCallback / useReducer / useImperativeHandle,用「算账 +
前端·javascript·react.js
Jackson__11 小时前
面试官:如何在老项目中使用新框架,并实现通信?
前端·javascript·面试
拾年27511 小时前
React Hooks 保姆级教程:把组件想象成失忆的打工人,4 个 Hook 带你原地起飞
前端·javascript·react.js
mmsx11 小时前
一个 Bug 修了 12 轮,根因只有一句话:AI 编程时代,日志才是唯一的真相
前端
默_笙11 小时前
😝 5 亿次循环卡死页面?我用 Web Worker 把它扔进后台线程,页面丝滑如初
前端·javascript
CAD老兵11 小时前
一行代码集成 DWG/DXF 图纸查看:测量批注,数据不出站
前端·javascript·github
小林ixn11 小时前
单例模式:从弹窗管理到全局状态,一个模式搞定
前端·javascript·设计模式
AI编程实验室11 小时前
Node.js Agent Handoff 仓库扫描 MVP:忽略规则、include 通配与稳定输出实现
前端·ai编程
猫不易11 小时前
从 Virtual DOM 到 Vapor:Vue 3.6 的另一条路
前端·vue.js
光影少年12 小时前
react navite性能优化 & 常见坑
前端·react native·掘金·金石计划