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>
相关推荐
天若有情67329 分钟前
开源|纯前端·条码&二维码在线生成器,支持拖拽缩放、复制生成码图片
前端·javascript·开源·html·二维码·条形码
map_vis_3d2 小时前
控制百度地图视野:setCenter、setZoom、panTo、flyTo 和 setViewport
前端·javascript·地图·百度地图
map_vis_3d3 小时前
百度地图 3D 视角:倾斜 tilt 与旋转 heading
前端·webgl·地图·百度地图·三维
Hilaku3 小时前
前端到底要不要写单元测试?
前端·javascript·程序员
ikoala3 小时前
每个独立开发者上线前,务必用这个skill做一次安全漏洞自查
前端·javascript·后端
anyup4 小时前
uni-app x 的 Signature 签名板与练字格,一个组件多端支持 App/鸿蒙/H5/小程序
前端·vue.js·uni-app
艾莉丝努力练剑4 小时前
【AI大模型接入SDK】项目总结
java·开发语言·前端·c++·人工智能·学习·架构
oil欧哟5 小时前
为什么我们不建议盲目构建多 Agent 系统
前端·后端
徐小夕5 小时前
从 RAG 工具到文档处理平台,聊聊 LlamaIndex 为什么成了 AI 应用的标配底座
前端·vue.js·github
map_3d_vis5 小时前
百度地图视角动画 ViewAnimation:按关键帧做飞行和环绕
前端·webgl·可视化·百度地图·三维