模拟微信小程序顶部导航栏
在调戏微信小程序的时候,被微信“可爱”的顶部导航栏给气到的,后来还是觉得自己整一个。
下面直接上代码,磨磨唧唧最娘们。
wmxl
实现背景色可调,可渐变,标题颜色可变,返回栏可隐藏
<view class="empty_custom" style="height:{{statusBarHeight}}px;background:white;background:{{bkcolor}};"></view>
<view class="custom naviView flexRow" style="margin-top:{{statusBarHeight}}px;background:{{bkcolor}};">
<view style="display:{{showArray?'flex':'none'}};align-items:center;color:{{fontcolor}};font-size:34rpx;" bindtap="returnbefore">
<view class="naviArray" style="border-bottom: 7rpx solid {{fontcolor}};border-right: 7rpx solid {{fontcolor}};"></view>
<view class="callback">返回</view>
</view>
<!-- <image class="personIcon" mode="scaleToFill" src="{{userInfo.avatarUrl}}"></image> -->
<view class="naviText {{showArray?'titleLeft':'titleCenter'}}" style="color:{{fontcolor}}">{{title}}</view>
</view>
wxss
.flexRow{
display: flex;
flex-direction: row;
justify-content: space-between;
}
.flexColumn{
display: flex;
flex-direction: column;
justify-content: space-between;
}
.empty_custom{
position: fixed;
width: 100%;
top: 0;
left: 0;
height: 90rpx;
background: white;
z-index: 999;
}
.custom{
min-height: 45px;
width: 100%;
align-items:center;
}
.naviView{
justify-content: flex-start;
background:white;
position:relative;
}
.naviText{
width:250rpx;
text-align: center;
font-size:36rpx;
font-family:PingFang-SC-Bold;
font-weight:bold;
color:rgba(0,0,0,1);
}
.naviArray{
margin-left:30rpx;
width:20rpx;
height:20rpx;
vertical-align: middle;
border-bottom: 7rpx solid white;
border-right: 7rpx solid white;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
transform: rotate(135deg);
/* background-color:white; */
}
.titleCenter{
flex: 1 1;
}
.callback{
vertical-align:middle;
display:inline-block;
}
.titleLeft{
flex: 1 1;
text-indent: -110rpx;
}
js
// pages/components/haedBar/headBar.js
const app = getApp();
Component({
/**
* 组件的属性列表
*/
properties: {
title: {
type: String,
value: ''
},
showArray: {
type: Boolean,
value:true
},
bkcolor:{
type: String,
value: 'white'
},
fontcolor:{
type: String,
value: 'black'
}
// bkcolor
},
/**
* 组件的初始数据
*/
data: {
//导航栏高度
statusBarHeight: app.globalData.statusBarHeight,
},
attached: function () {
},
/**
* 组件的方法列表
*/
methods: {
returnbefore:function(){
wx.navigateBack({
delta: 1
})
}
}
})
使用
<headBar title="xxx" showArray="{{showArray}}" bkcolor="black" fontcolor="white"/>
喜欢的话,点个赞,交个友。 留言板留下联系方式。