小程序custom-tab-bar自定义背景图片

踩了一天的坑,终于把这该死的自定义custom-tab-bar啃下来了,代码如下

<cover-image  class="background-bottom  {{isIphoneX?'phone':''}}" src="/image/tab/tab_bgc.png"></cover-image>
<cover-view wx:if="{{isIphoneX}}" class="tab-bar-backgrond"></cover-view>  

<cover-view class="tab-bar">
  <cover-view class="tab-bar-border"></cover-view>
  <cover-view wx:for="{{list}}" wx:key="index" class="tab-bar-item {{item.type == 'vcode' ? 'item-vcode' : ''}} {{isIphoneX?'phone-item':''}}" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
    <cover-image src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></cover-image>
    <cover-view  style="color: {{selected === index ? selectedColor : color}};">{{item.text}}</cover-view>
  </cover-view>
</cover-view>
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 86px;    
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 3;
}
.tab-bar .background-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 750rpx;
  height: 86px;
  z-index: 0;
}
 .phone{
  position: fixed;
  bottom: 0rpx;
  left: 0;
  width: 750rpx;
  height: 86px;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 0;
}

.tab-bar-backgrond {
  position: absolute;
  bottom: -50px;
  left: 0;
  width: 750rpx;
  height: 107px;
  background-color: #fff;
}

.tab-bar-border {
  display: none;
}

.tab-bar-item {
  flex: 1;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  padding-top: 40px;
  position: relative;
  z-index: 1;
}

.tab-bar-item.item-vcode cover-view {
  color: rgba(214, 24, 25, 1) !important;
}

.tab-bar-item cover-image {
  width: 27px;
  height: 27px;
}


.tab-bar-item .item-vcode cover-image {
  width: 42px;
  height: 42px;
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translate(-50%, 0);
}

.tab-bar-item cover-view {
  font-size: 10px;
}

.tab-bar-item.item-vcode cover-view {
  margin-top: 24px;
}
.redcolor{
  color: rgba(214, 24, 25, 1);
}
.tab-bar-item.item-vcode cover-image {
  width: 65px;
  height: 65px;
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translate(-50%, 0);
}
.tab-bar-item.phone-item cover-image {
  top: 0px;
}

效果图在这里插入图片描述
在这里插入图片描述
阴影效果需要图片自带阴影!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小张很嚣张~

支持一下小老弟吧~

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

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

打赏作者

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

抵扣说明:

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

余额充值