微信小程序自定义tabBar详细教程,且自适应尺寸和实现高斯模糊版

进入下面小程序可以体验效果

 

1、需要在app.json配置

custom 必须是true

PS:自定义tab-bar里面的JS中自定义的list 数量必须要和 app.json 中的list数量相同!!

"tabBar": {
    "custom": true,
    "selectedColor": "#33a3dc",
    "list": [
      {
        "iconPath": "asset/imge/hu.png",
        "selectedIconPath": "asset/imge/hu-fill.png",
        "pagePath": "pages/index/index",
        "text": "心动"
      },
      {
        "iconPath": "asset/imge/per.png",
        "selectedIconPath": "asset/imge/per-fill.png",
        "pagePath": "pages/my/my",
        "text": "我的"
      }
    ]
  },

2、根目录新建文件夹

必须是 “custom-tab-bar” 这个名字

custom-tab-bar/index ,必须是index

然后该文件夹目录下的代码

WXML代码:

<view class="tabbar">
    <block wx:for="{{ list }}" wx:key="index">
        <view class="tabbar-item " 
            data-page="{{ item.pagePath }}"
            data-index="{{ index }}"
            bindtap="selectPage"
        >
                <image class="tabbar-item-image" src="{{ select === index ?  item.selectedIconPath : item.iconPath }}"></image>
                <text class="tabbar-item-text" style="{{select==index?item.textColor:''}}">{{ item.text }}</text>
        </view>
    </block>
</view>

 js代码:

const app = getApp()
Component({
  data: {
      select: 0,
      list: [
          {
            iconPath: "/asset/imge/hu.png",
            selectedIconPath: "/asset/imge/hu-fill.png",
            pagePath: "/pages/index/index",
            text: "心动",
            textColor:"color:#ef3166;"
          },
         {
            iconPath: "/asset/imge/per.png",
            selectedIconPath: "/asset/imge/per-fill.png",
            pagePath: "/pages/my/my",
            text: "我的",
            textColor:"color:#0a993a;"
         }
      ]
  },
  methods: {
      selectPage(e) {
          const { page,index } = e.currentTarget.dataset;
          this.setData({select:index})
          wx.nextTick(()=>{
            wx.switchTab({
              url: page,
              complete:(res)=>{
                res['pagePath'] = page
                res['index'] = index
                this.triggerEvent('selectPage', res, {})
              }
            })
          })
      }
  }
})

wxss代码:

高斯模糊代码

backdrop-filter: blur(10px);

background-color: rgb(0 0 0 / .10);

.tabbar {
  width: 100%;
  display: flex;
  backdrop-filter: blur(10px);
  background-color: rgb(0 0 0 / .10);
  position: fixed;
  bottom: 0;
  padding-top: 10rpx;
  z-index: 9999;
  box-shadow: 0rpx -2rpx 20rpx 2rpx rgba(165,165,165,0.34);
  background-color: rgba(238, 238, 238, 0.89);
  padding-bottom:calc(10rpx + env(safe-area-inset-bottom) / 2);
  pointer-events: auto; //skyline 模式必须使用,否则异常。skyline模式本身BUG
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #7c7c7c;
}

.tabbar-item-image {
  width: 50rpx;
  height: 50rpx;
}

.tabbar-item-text {
  font-size: 28rpx;
  margin-top: 1rpx;
}

.tabbar-select {
  color: #0a993a;
}

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Qensq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值