uniapp自定义头部导航栏布局(普通版)

H5与微信小程序

通过获取系统信息和获取胶囊按钮的信息,得到获取标题栏高度,成而做好自定义头部导航栏

在微信小程序可使用

但在H5就保错,就需要优化

<!-- 全局custom-nav-bar组件 -->
<template>
	<view class="customNavBar">
		<view class="navbar">
			<!-- 状态栏 -->
			<view class="statusBar" :style="{height:statusBarHeight + 'px'}"> </view>
			<!-- 标题栏 -->
			<view class="titleBar" :style="{height:titleBarHeight + '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:statusBarHeight +titleBarHeight+ 'px'}">
			
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { onShow } from "@dcloudio/uni-app";
	//获取系统信息
	let systemInfo = uni.getSystemInfoSync();
	//获取状态栏的高度
	let statusBarHeight=ref(systemInfo.statusBarHeight)
	//获取胶囊按钮的信息
	// let menuButton =uni.getMenuButtonBoundingClientRect()
	let {top,height}=uni.getMenuButtonBoundingClientRect();
	// console.log(top,height,statusBarHeight)//24 32 20
	//获取标题栏高度
	let titleBarHeight= ref((top-statusBarHeight.value)*2 + height)//40
</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>

记得在Layoutindex.vue引入

<view class="layout pageColor">
		<custom-nav-bar></custom-nav-bar>
		<!-- 轮播图 -->
		//....
</view>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值