当前位置: 首页 > article >正文

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>

在这里插入图片描述


http://www.kler.cn/a/595921.html

相关文章:

  • DigitalFoto公司如何用日事清流程管理工具实现任务优先级与状态可视化?
  • 平衡树的模拟实现
  • cursor常用快捷键(JetBrains Darcula主题风格)
  • 【赵渝强老师】达梦数据库MPP集群的架构
  • 记录瞬间:面试中的技术碰撞与思考
  • 昆仑万维开源Skywork R1V:多模态推理模型的革命性突破
  • STM32 系统滴答定时器
  • Node.js系列(2)--性能优化指南
  • Redis 主从架构与哨兵高可用方案实操
  • Axure大屏可视化模板:赋能多领域,开启数据展示新篇章
  • flask gunicorn 日志部署
  • 【网络安全基础学习】渗透测试工具--Burp Suite详细教程
  • NLP高频面试题(八)——GPT三个版本的区别
  • 构建高可靠NFS存储:自动化挂载保障机制的设计与优势
  • 多模态AI落地:从理论到智能客服的完整实现
  • 学习CSS滤镜属性 `filter: invert()`
  • python 数据可视化TVTK库安装与使用
  • 24集《不负美食不负卿》联合出品制作签约仪式成功举行
  • 科技赋能安全:慧通测控的安全带全静态性能测试
  • 【PCB工艺】晶体管的发展历史