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