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>
相关推荐
Nymph_Zhu32 分钟前
pdf转换markdown预览及内容互相点击定位
前端·pdf·vue3·markdown·element-plus
计算机魔术师37 分钟前
Google 一天蒸发5000亿,Reddit 靠 AI 训练喂得饱自己却饿死
前端
小大宇43 分钟前
Vue知识点-ElementPlus-05 输入框
前端·javascript·vue.js
外贸GEO优化1 小时前
外贸独立站的可抓取性:JS 渲染、懒加载与无限滚动到底影响什么
开发语言·javascript·ecmascript
l1m0_1 小时前
AI设计工具有哪些?Paico、Pixso AI、墨刀AI、Lovable、Codex怎么选
前端·人工智能·ai·设计·墨刀·codex·pixso
web打印社区1 小时前
Lodop在Edge和双核浏览器-先分清内核
前端·javascript·edge·pdf·ecmascript·html5
系统集成-鹰翔1 小时前
ERP对接升级提示数据库迁移失败:SQLite逐版本事务到底回滚到哪一步
javascript·数据库·经验分享·后端
西瓜拿铁好喝1 小时前
开源和闭源 AI 办公工具,分别适合谁
java·前端·数据库
IT_陈寒1 小时前
深入理解SpringBoot:核心原理与最佳实践
前端·人工智能·后端
风骏时光牛马2 小时前
大模型综合能力多维评测:性能、逻辑与落地表现对比
前端