├── .gitignore
├── README.md
├── app.js
├── app.json
├── components
└── navbar
│ ├── img
│ ├── back.svg
│ └── home.svg
│ ├── navbar.js
│ ├── navbar.json
│ ├── navbar.wxml
│ └── navbar.wxss
├── index
├── index.js
├── index.json
├── index.wxml
└── index.wxss
├── project.config.json
├── screenshot
├── navbar_1.png
├── navbar_2.png
└── navbar_3.png
└── sitemap.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
微信小程序自定义导航栏(wx_custom_navigation_bar)
2 | 可选择返回键、首页键,动态设置标题,响应式组件
3 | 版本号:1.0.0
4 | 作者:chen-yt
5 |
6 | ## 截图
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | App({
2 | onLaunch() {
3 | console.log('微信小程序自定义导航栏:https://github.com/chen-yt/wx_custom_navigation_bar')
4 | }
5 | })
6 |
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "index/index"
4 | ],
5 | "window": {
6 | "backgroundTextStyle": "light",
7 | "navigationStyle": "custom"
8 | },
9 | "sitemapLocation": "sitemap.json"
10 | }
--------------------------------------------------------------------------------
/components/navbar/img/back.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/components/navbar/img/home.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/components/navbar/navbar.js:
--------------------------------------------------------------------------------
1 | const navBarHeight = wx.getSystemInfoSync().statusBarHeight + 44
2 |
3 | Component({
4 |
5 | properties: {
6 | back: {
7 | type: Boolean,
8 | value: false
9 | },
10 | home: {
11 | type: Boolean,
12 | value: false
13 | },
14 | title: {
15 | type: String,
16 | value: 'Wechat'
17 | },
18 | titleColor: {
19 | type: String,
20 | value: '#ffffff'
21 | },
22 | background: {
23 | type: String,
24 | value: '#2f2f2f'
25 | }
26 | },
27 |
28 | data: {
29 | navBarHeight
30 | },
31 |
32 | methods: {
33 | home() {
34 | this.triggerEvent('home')
35 | wx.reLaunch({
36 | url: '/index/index'
37 | })
38 | },
39 |
40 | back() {
41 | this.triggerEvent('back')
42 | if (getCurrentPages().length === 1) {
43 | wx.redirectTo({
44 | url: '/index/index'
45 | })
46 | } else {
47 | wx.navigateBack()
48 | }
49 | }
50 | }
51 | })
52 |
--------------------------------------------------------------------------------
/components/navbar/navbar.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
--------------------------------------------------------------------------------
/components/navbar/navbar.wxml:
--------------------------------------------------------------------------------
1 |
5 | {{title}}
6 |
7 |
8 |
14 |
15 |
21 |
22 |
23 |
24 |
28 |
29 |
--------------------------------------------------------------------------------
/components/navbar/navbar.wxss:
--------------------------------------------------------------------------------
1 | .navbar {
2 | position: fixed;
3 | left: 0;
4 | right: 0;
5 | top: 0;
6 | z-index: 10;
7 | }
8 |
9 | .title {
10 | position: absolute;
11 | bottom: 22px;
12 | left: 104px;
13 | right: 104px;
14 | transform: translateY(50%);
15 | font-size: 14px;
16 | text-align: center;
17 | overflow: hidden;
18 | text-overflow: ellipsis;
19 | white-space: nowrap;
20 | }
21 |
22 | .capsule {
23 | position: absolute;
24 | left: 16px;
25 | bottom: 22px;
26 | transform: translateY(50%);
27 | height: 32px;
28 | display: flex;
29 | align-items: center;
30 | }
31 |
32 | .capsule > image {
33 | width: 20px;
34 | height: 20px;
35 | }
36 |
37 | .capsule > image:nth-child(2) {
38 | margin-left: 12px;
39 | }
40 |
41 | .page {
42 | position: fixed;
43 | left: 0;
44 | right: 0;
45 | bottom: 0;
46 | }
--------------------------------------------------------------------------------
/index/index.js:
--------------------------------------------------------------------------------
1 | const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
2 |
3 | Page({
4 | data: {
5 | isShowBack: true,
6 | isShowHome: true,
7 | title: '小程序自定义导航栏',
8 | titleColor: '#ffffff',
9 | background: 'linear-gradient(135deg, #33B3F3 0%, #2070DC 100%)'
10 | },
11 |
12 | onBack() {
13 | console.log('导航栏被点击返回')
14 | },
15 |
16 | onHome() {
17 | console.log('导航栏被点击首页')
18 | },
19 |
20 | changeTitle() {
21 | this.setData({
22 | title: '标题很长,溢出自动隐藏~'
23 | })
24 | },
25 |
26 | changeBackground() {
27 | this.setData({
28 | background: '#2f2f2f'
29 | })
30 | },
31 |
32 | changeColor() {
33 | this.setData({
34 | titleColor: 'blue'
35 | })
36 | },
37 |
38 | changeBackBtn() {
39 | this.setData({
40 | isShowBack: !this.data.isShowBack
41 | })
42 | },
43 |
44 | changeHomeBtn() {
45 | this.setData({
46 | isShowHome: !this.data.isShowHome
47 | })
48 | }
49 | })
50 |
--------------------------------------------------------------------------------
/index/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {
3 | "navbar": "../../components/navbar/navbar"
4 | },
5 | "disableScroll": true
6 | }
--------------------------------------------------------------------------------
/index/index.wxml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/index/index.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chen-yt/wx_custom_navigation_bar/fa3c24d38e93cf8564f2c9fa4f2df41705f95050/index/index.wxss
--------------------------------------------------------------------------------
/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件",
3 | "packOptions": {
4 | "ignore": []
5 | },
6 | "setting": {
7 | "urlCheck": true,
8 | "es6": true,
9 | "postcss": true,
10 | "minified": true,
11 | "newFeature": true
12 | },
13 | "compileType": "miniprogram",
14 | "libVersion": "2.3.2",
15 | "appid": "wxb36c11bb08b72a15",
16 | "projectname": "navigation_bar",
17 | "debugOptions": {
18 | "hidedInDevtools": []
19 | },
20 | "isGameTourist": false,
21 | "simulatorType": "wechat",
22 | "simulatorPluginLibVersion": {},
23 | "condition": {
24 | "search": {
25 | "current": -1,
26 | "list": []
27 | },
28 | "conversation": {
29 | "current": -1,
30 | "list": []
31 | },
32 | "game": {
33 | "currentL": -1,
34 | "list": []
35 | },
36 | "miniprogram": {
37 | "current": -1,
38 | "list": []
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/screenshot/navbar_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chen-yt/wx_custom_navigation_bar/fa3c24d38e93cf8564f2c9fa4f2df41705f95050/screenshot/navbar_1.png
--------------------------------------------------------------------------------
/screenshot/navbar_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chen-yt/wx_custom_navigation_bar/fa3c24d38e93cf8564f2c9fa4f2df41705f95050/screenshot/navbar_2.png
--------------------------------------------------------------------------------
/screenshot/navbar_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chen-yt/wx_custom_navigation_bar/fa3c24d38e93cf8564f2c9fa4f2df41705f95050/screenshot/navbar_3.png
--------------------------------------------------------------------------------
/sitemap.json:
--------------------------------------------------------------------------------
1 | {
2 | "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
3 | "rules": [{
4 | "action": "allow",
5 | "page": "*"
6 | }]
7 | }
--------------------------------------------------------------------------------