微信导航条html,微信小程序 自定义导航栏(1)(示例代码)

1.在app.json中     window配置navigationStyle

02b845bbe4cf429386e212cb59b4164e.jpg

2.计算相关值

a6709848a1264f6592788fadba582433.jpg

1. 整个导航栏的高度;

2. 胶囊按钮与顶部的距离;

3. 胶囊按钮与右侧的距离。

小程序可以通过 wx.getMenuButtonBoundingClientRect()获取胶囊按钮的信息  和 wx.getSystemInfo()获取设备信息

通过这些信息我们可以计算出上面说的3个值:

1. 整个导航栏高度 = statausBarHeight + height + (top-statausBarHeight )*2;

2. 胶囊按钮与顶部的距离 = top;

3.胶囊按钮与右侧的距离 = windowWidth - right。

App.js 代码如下:

2cc15d4c04054d46afdceb3a09eecf7f.jpg

3.头部组件navBar

75a3848444d0491ebffd45f6073e7d37.jpg

navBar.wxml

{{pageName}}

navBar.wxss

.navbar{width:100%;overflow:hidden;position:relative;top:0;left:0;z-index:10;flex-shrink:0;background:#fff;

}.navbar_left{display:-webkit-flex;display:flex;-webkit-box-align:center;-ms-flex-align:center;-webkit-align-items:center;align-items:center;position:absolute;left:10px;z-index:11;line-height:1;padding:3px;border:1rpx solid #f0f0f0;border-radius:40rpx;overflow:hidden;background:rgba(255,255,255,0.6);

}.navbar_left view{width:50rpx;height:50rpx;margin-right:10rpx;

}.navbar_left view image{width:100%;height:100%;

}.nav_line{border-left:1rpx solid #f0f0f0;padding-left:8px;

}.navbar_title{width:100%;box-sizing:border-box;padding-left:115px;padding-right:115px;height:32px;line-height:32px;text-align:center;position:absolute;left:0;z-index:10;color:#333;font-size:16px;font-weight:bold;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;

}

navBar.js

const App =getApp();

Component({/**

* 组件的属性列表*/properties: {

pageName: String,//中间的title

showNav: { //判断是否显示左上角的按钮

type: Boolean,

value:true},

showHome: {//判断是否显示左上角的home按钮

type: Boolean,

value:true}

},/**

* 组件的初始数据*/data: {

showNav:true, //判断是否显示左上角的home按钮

showHome: true, //判断是否显示左上角的按钮

},

lifetimes: {//生命周期函数,可以为函数,或一个在methods段中定义的方法名

attached: function() {this.setData({

navHeight: App.globalData.navHeight,

navTop: App.globalData.navTop

})

}

},/**

* 组件的方法列表*/methods: {//回退

navBack: function() {

wx.navigateBack()

},//回主页

navHome: function() {

wx.navigateTo({

url:\'/pages/home/home\'})

},

}

})

navBar.json

3c9eb17b586245308099d66e51714329.jpg

4.index中

index.json

025f1c7a62064f209583fe3d6e42880d.jpg

index.wxml

跳转

index.js

429b06ae727143ce8a432ba975b2c912.jpg

5.demo1中

demo1.wxml

d892cf169a48467dbe25f43b638e2deb.jpg

demo.js

04a3095d03bd495ca29f14bf99975c42.jpg

6.home页

home.wxml

3bd5f2dd15d9459b9a96eb5a6c0296c5.jpg

home.js

fa58a7c21c6241818826302515a7ec83.jpg

最后效果图:

7123e956d96b411a9ac19c1d5102a803.jpg

93fdf240b9ce4f309265e16adc14b777.jpg

5fb04a61043643ef8447274c1cc453db.jpg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值