微信小程序自定义顶部导航栏,动态适状态栏标题包括胶囊

微信小程序自定义顶部导航栏,动态适配包括胶囊

html 复制代码
<view>
	<uni-nav-bar :height="totalHeight" backgroundColor="#FFC003" leftWidth="100%">
			<block slot="left">
				<view>
					<view class="navTitle">
						哈哈哈
					</view>
				</view>
			</block>
		</uni-nav-bar>
</view>
javascript 复制代码
menu: [],
statusBarHeight: 0, //状态栏的高度 
navigatorHeight: 0, //导航栏高度
menuHeight: 0, //胶囊高度
menuTop: 0, //胶囊与顶部的距离
totalHeight: 0, //总高度 
onShow() {
	// 获取系统信息
	uni.getSystemInfo({
		success: res => {
			this.system = res;
			this.statusBarHeight = this.system.statusBarHeight; // 状态栏高度
			this.calculateNavBarHeight()
		}
	});
},
methods:{
	calculateNavBarHeight() {
		// 获取胶囊信息
		this.menu = uni.getMenuButtonBoundingClientRect();
		// 计算组件高度
		this.menuHeight = this.menu.height; // 胶囊高度
		this.menuTop = this.menu.top; // 胶囊与顶部的距离
		// 导航栏高度= (胶囊顶部距离-状态栏高度) x 2 + 胶囊的高度
		this.navigatorHeight = (this.menu.top - this.system.statusBarHeight) * 2 + this.menu.height;
		// 总高度 = 状态栏的高度 + 导航栏高度    
		this.totalHeight = this.statusBarHeight + this.navigatorHeight;
	 },
}
css 复制代码
	.navTitle {
		padding-left: 36rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 36rpx;
		color: #000000;
		margin-bottom: 10rpx;
	}
相关推荐
咖啡の猫11 小时前
微信小程序页面事件
微信小程序·小程序·notepad++
咖啡の猫13 小时前
微信小程序网络数据请求
网络·微信小程序·小程序
object not found13 小时前
基于uniapp开发小程序自定义顶部导航栏状态栏标题栏
前端·javascript·小程序·uni-app
咖啡の猫13 小时前
微信小程序案例 - 本地生活(列表页面)
微信小程序·生活·notepad++
咖啡の猫14 小时前
微信小程序案例 - 本地生活(首页)
微信小程序·生活·notepad++
咸虾米_15 小时前
uniapp引入iconfont字体图标在微信小程序中适用
微信小程序·小程序·uni-app
咖啡の猫16 小时前
微信小程序页面导航
微信小程序·小程序
小咕聊编程16 小时前
【含文档+PPT+源码】基于微信小程序的点餐系统的设计与实现
微信小程序·小程序
2501_915918411 天前
如何在iPad上找到并打开文件夹的完整指南
android·ios·小程序·uni-app·iphone·webview·ipad
shejizuopin1 天前
基于Spring Boot+小程序的非遗科普平台设计与实现(毕业论文)
spring boot·后端·小程序·毕业设计·论文·毕业论文·非遗科普平台设计与实现