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>
相关推荐
cyadyx1 分钟前
【vue】Pinia相对Vuex
前端·javascript·vue.js
码上成长12 分钟前
小程序请求层怎么封装?
前端·小程序
IT_陈寒35 分钟前
Redis的KEYS命令差点把我的生产环境拖垮,改用SCAN吧
前端·人工智能·后端
deli00700740 分钟前
打飞碟射击场:霓虹星空下飞碟满天飞,鼠标点射一枪一个
前端·ai编程
zoe驿鹿1 小时前
【CI/CD】前端工程化与自动化:从“手工作坊”到“现代化工厂”的演进之路
前端·ci/cd·自动化
lupai1 小时前
增值税发票 OCR 识别 API 新手接入指南
java·前端·ocr
IMPYLH1 小时前
HTML 的 <figure> 元素
前端·javascript·html
reasonsummer1 小时前
【办公类-120-01】20260812闵行区幼儿园概况表的数据统计(户籍、五类性质、优抚子女)
前端·python
宿6741 小时前
vue3-指令和事件处理
开发语言·前端·javascript
风骏时光牛马1 小时前
AI助手异常问题Debug排查
前端