首页 > 其他分享 >uniapp自定义头部导航栏布局(优化版)

uniapp自定义头部导航栏布局(优化版)

时间:2024-08-30 20:21:27浏览次数:6  
标签:uniapp const 自定义 statusBarHeight getStatusBarHeight uni font 导航 left

H5与微信小程序效果图

普通版

//utils/system.js

	//获取系统信息
	const systemInfo = uni.getSystemInfoSync();
	//获取状态栏的高度,H5状态栏的高度默认是0
	export const getStatusBarHeight=()=>systemInfo.statusBarHeight || 0;
	//获取标题栏高度
	export const getTitleBarHeight =()=>{
		// 再次获取状态栏的高度
		 const statusBarHeight = getStatusBarHeight();
		//判断是否有胶囊按钮
		if(uni.getMenuButtonBoundingClientRect){
			let {top,height}=uni.getMenuButtonBoundingClientRect()
			return (top-statusBarHeight)*2 + height
		}else{
			return 40;
		}
	}
	
	//填充区域
	export const getNavBarHeight =()=>getStatusBarHeight() + getTitleBarHeight()
<template>
	<view class="customNavBar">
		<view class="navbar">
			<!-- 状态栏 -->
			<view class="statusBar" :style="{height:getStatusBarHeight() + 'px'}"> </view>
			<!-- 标题栏 -->
			<view class="titleBar" :style="{height:getTitleBarHeight() + 'px'}">
				<view class="title">标题</view>
				<view class="search">
					<uni-icons type="search" color="#888" size="18" class="icon"></uni-icons>
					<text class="text">搜索</text>
				</view>
			</view>
		</view>
		<!-- 填充区域 -->
		<view class="fill"  :style="{height:getNavBarHeight()+ 'px'}">
			
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { onShow } from "@dcloudio/uni-app";
// 引入自定义头部导航栏相关信息
	import {getStatusBarHeight,getTitleBarHeight,getNavBarHeight} from "@/utils/system.js"
</script>

<style lang="scss" scoped>
.customNavBar{
	.navbar{
		position: fixed;
		top:0;
		left: 0;
		width: 100%;
		z-index: 20;
		background:
		linear-gradient(to bottom,rgba(0,0,0,0),#fff 400rpx),
		linear-gradient(to right, #beecd8 20%,#F4E2d8);
		.statusBar{}
		.titleBar{
			display: flex;
			padding-left: 30rpx;
			align-items: center;
			.title{
				font-size: 22px;
				font-weight: 600;
				color: $text-font-color-1;
			}
		}
		.search{
			  width: 220rpx;
			 height: 50rpx;
			 border-radius: 60rpx;
			 background: rgba(255,255,255,0.4);
			 border:1px solid #fff;
			 margin-left:30rpx;
			 color:#999;
			font-size: 28rpx;
			display: flex;
			align-items: center;
			 .icon{
					  margin-left:5rpx;
				  }
				  .text{
					  padding-left:10rpx;
				  }
		}
	}
}
</style>

标签:uniapp,const,自定义,statusBarHeight,getStatusBarHeight,uni,font,导航,left
From: https://blog.csdn.net/2301_76917834/article/details/141532251

相关文章

  • 自定义深度渲染实现物体描边
    自定义深度渲染实现物体描边SceneTexture首先我们要先了解清楚关于深度渲染的几个属性的含义SceneTexture(场景纹理)节点:通过这个节点,输入UV值,你可以获取到这个UV对应的像素点的各个属性,比如SceneColor(场景颜色),SceneDepth(场景深度),CustomDepth(自定义深度),Opacity(不透明度)等......
  • HarmonyOS开发指南:ArkUI自定义Toast弹窗样式规范
     可以通过使用自定义弹窗和定时器达到类似Toast的效果。场景一:自定义弹窗实现弹窗中加入icon和文字,支持Button。方案:⦁   使用@CustomDialog装饰器装饰自定义弹窗,在此装饰器内进行自定义内容(也就是弹框内容)、并创建构造器,与装饰器呼应相连。⦁   使用定时器,在页面......
  • uniapp 微信小程序 支付
    <template> <viewclass="wrap">  <viewclass="payComplete">   <imageclass="img"src="@/static/image/index/6.png"/>   <textclass="adress">支付完成后填写</text> ......
  • CSS、JS之滚动导航栏
    效果演示实现了一个滚动导航栏,包括一个固定在页面顶部的导航栏和四个全屏高度的区块。导航栏的背景颜色为半透明黑色,高度为60px,导航链接为白色,字体大小为30px,链接之间有15px的间距。当鼠标悬停在链接上时,下划线会出现。四个区块的背景颜色分别为#95e1d3、#eaffd0、#fce38a......
  • uniapp js 划消小游戏 1.0 去控制台看打印(仅作参考)
    <template> <viewclass="wrap">  划消:{{sdNum}}*{{sdNum}}  <viewclass="btn"style="padding:32rpx;background:pink"@click="clickBtn">点击划消按钮</view>  <viewclass="btn&q......
  • uniapp js 数独小游戏 写死的简单数独 数独 3.0
    <template> <viewclass="wrap">  数独:{{sdNum}}*{{sdNum}}  <viewclass="btn"style="padding:32rpx;background:pink"@click="startFun">点击开始计时</view>  <viewclass="btn&q......
  • vite3接入vue-quill:处理图片,自定义字体和字体大小,切换源码模式
    环境适用版本:node:14.21.2"vue":"^3.2.26""vite":"^3.1.0"安装模块:"@vueup/vue-quill":"^1.2.0","quill-html-edit-button":"^3.0.0","quill-image-resize-module":"^3......
  • 自定义TextView实现首尾相接跑马灯效果
    需求:TextView内容不满一行的时候不滚动,超过一行的时候缓慢滚动到最后,然后添加空白间隔继续滚动(我们项目用的是三个View一块滚动,停止应该是不一块停止的,毕竟三条内容应该不一样长,所以就需要个监听是否都停止了,如果都停止了,就一块开启继续滚动)importandroid.animation.Animato......
  • ROS 简单导航
        导航是现代机器人可以说是必备的功能,很多机器人都不可以缺少这个功能,本文仍然是通过ros的topic话题通讯机制,结合了map和导航相关的话题,通过手动设置目标点,完成了对于机器人导航的控制。    1.首先需要导包:importrospyimportactionlibfrommove_base_m......
  • 金蝶云星空组织间结算清单增加自定义字段说明
    单据增加字段相关结算单增加,基础资料控件,映射资料。 业务单据-其他出库单增加字段 配置功能特性   创建结算清单时,会生成到自定义字段上      ......