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>
相关推荐
余人于RenYu3 小时前
Claude + Figma MCP
前端·ui·ai·figma
杨艺韬6 小时前
vite内核解析-第2章 架构总览
前端·vite
我是伪码农7 小时前
外卖餐具智能推荐
linux·服务器·前端
2401_885885047 小时前
营销推广短信接口集成:结合营销策略实现的API接口动态变量填充方案
前端·python
小李子呢02117 小时前
前端八股性能优化(2)---回流(重排)和重绘
前端·javascript
程序员buddha8 小时前
深入理解ES6 Promise
前端·ecmascript·es6
吴声子夜歌8 小时前
ES6——Module详解
前端·ecmascript·es6
剪刀石头布啊8 小时前
原生form发起表单干了啥
前端
剪刀石头布啊8 小时前
表单校验场景,如何实现页面滚动到报错位置
前端
gyx_这个杀手不太冷静8 小时前
大人工智能时代下前端界面全新开发模式的思考(二)
前端·架构·ai编程