当前位置:网站首页>[wechat applet custom bottom tabbar]
[wechat applet custom bottom tabbar]
2022-06-22 16:37:00 【Chang'an CC】


app.js
{
"pages": [
"pages/index/index",
"pages/saleMng/saleMng",
"pages/newsMng/newsMng",
"pages/my/my"
],
"tabBar": {
"custom": true,
"color": "#6b6c75",
"selectedColor": "#FF3B3B",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "/img/icon/tabIcon1.png",
"selectedIconPath": "/img/icon/tabIcon1-.png",
"text": " home page "
},
{
"pagePath": "pages/saleMng/saleMng",
"iconPath": "/img/icon/tabIcon2.png",
"selectedIconPath": "/img/icon/tabIcon2-.png",
"text": " Purchase and sale "
},
{
"pagePath": "pages/newsMng/newsMng",
"iconPath": "/img/icon/tabIcon4.png",
"selectedIconPath": "/img/icon/tabIcon4-.png",
"text": " news "
},
{
"pagePath": "pages/my/my",
"iconPath": "/img/icon/tabIcon5.png",
"selectedIconPath": "/img/icon/tabIcon5-.png",
"text": " my "
}
]
},
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"sitemapLocation": "sitemap.json"
}
custom-tab-bar/index.wxml
<!--custom-tab-bar/index.wxml-->
<view class="tab-bar">
<!-- <view class="tab-bar-border"></view> -->
<!-- -->
<block wx:for="{
{list}}" wx:key="index">
<div wx:if="{
{item.isSpecial == true}}" class="tabbar_nav" hover-class="none" style="color:{
{tabbar.selectedColor}}" open-type="navigate">
<view class='special-wrapper'>
<image class="tabbar_icon" src="{
{item.iconPath}}"></image>
</view>
<image class='special-text-wrapper'></image>
<text>{
{
item.text}}</text>
</div>
<view wx:else class="tab-bar-item" data-path="{
{item.pagePath}}" data-index="{
{index}}" bindtap="switchTab">
<!-- <view wx:for="{
{list}}" wx:key="index" class="tab-bar-item" data-path="{
{item.pagePath}}" data-index="{
{index}}" bindtap="switchTab"> -->
<image src="{
{selected === index ? item.selectedIconPath : item.iconPath}}" class="tabIcon"></image>
<view style="color: {
{selected === index ? selectedColor : color}}">{
{
item.text}}</view>
</view>
</block>
</view>
custom-tab-bar/index.js
Component({
data: {
selected: 0,
color: "#6b6c75",
selectedColor: "#FF3B3B",
list: [{
pagePath: "/pages/index/index",
iconPath: "/img/icon/tabIcon1.png",
selectedIconPath: "/img/icon/tabIcon1-.png",
text: " home page "
},
{
pagePath: "/pages/saleMng/saleMng",
iconPath: "/img/icon/tabIcon2.png",
selectedIconPath: "/img/icon/tabIcon2-.png",
text: " Purchase and sale "
},
{
// pagePath: "/pages/index1/index1",
iconPath: "/img/icon/tabIcon3.png",
isSpecial: true,
text: ""
},
{
pagePath: "/pages/newsMng/newsMng",
iconPath: "/img/icon/tabIcon4.png",
selectedIconPath: "/img/icon/tabIcon4-.png",
text: " news "
},
{
pagePath: "/pages/my/my",
iconPath: "/img/icon/tabIcon5.png",
selectedIconPath: "/img/icon/tabIcon5-.png",
text: " my "
}
]
},
attached() {
},
methods: {
switchTab(e) {
const data = e.currentTarget.dataset
const url = data.path
wx.switchTab({
url
})
// this.setData({
// selected: data.index
// })
}
}
})
custom-tab-bar/index.json
{
"component": true
}
custom-tab-bar/index.wxss
.tab-bar {
font-size: 10px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 48px;
background: white;
display: flex;
padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar-border {
background-color: rgba(0, 0, 0, 0.33);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 1px;
transform: scaleY(0.5);
}
.tab-bar-item {
flex: 1;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.tabIcon {
width:44rpx;
height:44rpx;
margin-bottom: 4rpx;
}
.tabbar_box {
display: flex;
flex-direction: row;
justify-content: space-around;
position: fixed;
bottom: 0;
left: 0;
z-index: 999;
width: 100%;
height: 98rpx;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.1);
}
.tabbar_box.iphoneX-height {
padding-bottom: 66rpx;
}
.middle-wrapper {
position: absolute;
right: 310rpx;
bottom: 0;
background-color: #fff;
width: 120rpx;
height: 120rpx;
border-radius: 50%;
border-top: 2rpx solid #f2f2f3;
}
.middle-wrapper.iphoneX-height {
bottom: 66rpx;
}
.tabbar_nav {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 20rpx;
height: 100%;
position: relative;
}
.tabbar_icon {
width: 56rpx;
height: 56rpx;
}
.special-wrapper {
position: absolute;
top: -28rpx;
width: 96rpx;
height: 96rpx;
border-radius: 50%;
/* border-top: 2rpx solid #f2f2f3; background-color: #fff; */
text-align: center;
box-sizing: border-box;
padding: 6rpx;
}
.special-wrapper .tabbar_icon {
width: 84rpx;
height: 84rpx;
}
.special-text-wrapper {
width: 56rpx;
height: 56rpx;
}
Key steps :
stay tabbar In page onshow Inside :
onShow: function () {
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
selected: 4
})
}
},
selected: 4( Corresponding to subscript order )
// pages/my/my.js
Page({
/** * Initial data of the page */
data: {
},
/** * Life cycle function -- Monitor page loading */
onLoad: function (options) {
},
/** * Life cycle function -- Listening page first rendering completed */
onReady: function () {
},
/** * Life cycle function -- Monitor page display */
onShow: function () {
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
selected: 4
})
}
},
/** * Life cycle function -- Monitor page hidden */
onHide: function () {
},
/** * Life cycle function -- Monitor page uninstall */
onUnload: function () {
},
/** * Page related event handler -- Monitor user pull-down action */
onPullDownRefresh: function () {
},
/** * Handling function of page pull bottom event */
onReachBottom: function () {
},
/** * Users click the upper right corner to share */
onShareAppMessage: function () {
}
})
边栏推荐
- 【C语言】深度剖析指针和数组的关系
- 面对默认导入失败的情况
- What is restful and what rules should be followed when designing rest APIs?
- NiO service multithreaded version
- SAP教程中的ALV报告 - ABAP列表查看器-012
- Summary of Changan chain usage skills
- What is the difference between "img" and "ALT" in the interview question
- SAP价值流程&帮助请求流程-011
- 接口(优化类型注解)
- Parts beyond the text are indicated by ellipsis
猜你喜欢

什么是 SAP ABAP? 类型、ABAP 完整形式和含义

SAP ABAP dialog programming tutorial: module pool in -09

SAP web service cannot log in to SOA management page with soamanager

Runtime -- explore the nature of classes, objects, and classifications

【微信小程序封装底部弹出框二】

10款超牛Vim插件,爱不释手了

2022年中国重卡智能化升级专题研究

jsp学习之(二)---------jsp脚本元素和指令

Smart forms-014 in SAP ABAP

短视频源码开发,优质的短视频源码需要做好哪几点?
随机推荐
5 modes of IO model
面对默认导入失败的情况
SAP web service 无法使用 SOAMANAGER 登陆到SOA管理页面
SAP ABAP table control and example-07
3. Classe abstraite (forme)
3.抽象類(shape)
过气剧本杀,被露营“复活”
SAP ABAP 中的模块化:宏、子程序和功能模块 -04
SAP ABAP BAPI-016
【C语言】深度剖析整型和浮点型在内存中的存储
【C语言】深度剖析指针和数组的关系
3. abstract class (shape)
Learning about ABAP program tuning (IV) loop where key
3.抽象类(shape)
nio文件和文件夹操作例子
数睿数据受邀参与南通企业数字化转型研讨会
1.类的继承(point)
What is SAP ABAP? Type, ABAP full form and meaning
Gd32f4xx MCU drives MCP2515 to expand can interface
Jsp Learning (2) - - jsp script Elements and instructions