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>
相关推荐
ShineWinsu4 小时前
对于JavaScript:操作元素的解析
开发语言·前端·javascript·面试·web·dom·元素
福兮说4 小时前
JSON 格式正确,数据就可靠吗?我用一份自编配置检查类型与空值
java·前端·json
程序员老赵6 小时前
Docker 部署青龙面板:轻松搭建定时任务管理平台
前端·docker·开源
Swot6 小时前
Asciidoctor 公式数字下标错位问题:原因分析与解决方案
前端
Swot6 小时前
leo-editor 中将 Markdown 内容转成 asciidoc 格式
前端
狒狒AI6 小时前
Remotion / GSAP+Three / HyperFrames / Skia 四栈实测:代码渲染知识视频的选栈方法(附开源技能)
前端·人工智能·aigc
修炼的dance7 小时前
浏览器里导出H.265,8.5秒和55.5秒差在硬件
前端
补码缩写7 小时前
WebCodecs选编码器,探测之后还要验解码和播放
前端
大文说跨境7 小时前
亚马逊多账号管理浏览器怎么选?云登/紫鸟/AdsPower 对比
java·前端·自动化
hunter_0767 小时前
iOS 首页复杂嵌套滚动技术方案:头部固定 + 网格滚动 + Tab 吸顶 + 每 Tab 独立下拉刷新
前端