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>
相关推荐
网络点点滴9 分钟前
Vue3 全局API转移到应用对象
前端·javascript·vue.js
波哥学开发11 分钟前
基于 OPFS 的前端缓存实践:图片与点云数据的本地持久化
前端
whuhewei13 分钟前
useCountDown (React Hooks)倒计时
前端·javascript·react.js
DanCheOo13 分钟前
流式输出:让 AI 回复像 ChatGPT 一样打字机效果
前端·全栈
HelloReader14 分钟前
Qt Quick 布局Positioners、Anchors 与 Layouts(九)
前端
HelloReader15 分钟前
Qt 信号与槽对象通信的核心机制(十)
前端
终端鹿18 分钟前
插槽(slot):默认插槽、具名插槽、作用域插槽实战
前端·javascript·vue.js
千百元19 分钟前
HBuilderX蓝牙功能打包有BUG
前端