微信小程序(六):伪tabbar的实现

微信小程序原生的tabbar一个项目只能有一个,我想要在多个页面都能使用不同的tabbar,就找到伪tabbar这种方法,通过点击元素实现页面跳转。

新建文件夹:

tabbarStudy.wxml

<view>
  <view>个人中心</view>
  <!-- 伪tabBar -->
  <view class='tabBar'>
    <view class='tabBar-left' catchtap='home'>
      <view class='tabBar-left-content-top'>
        <image class='tabBar-left-content-img' src='../../../images/home_out.png'/>
      </view>
      <view class='tabBar-left-content-bottom'>
        <label class='tabBar-left-content-label'>首页</label>
      </view>
    </view>
    <view class='tabBar-right' catchtap='mine'>
      <view class='tabBar-right-content-top'>
        <image class='tabBar-right-content-img' src='../../../images/my_in.png'/>
      </view>
      <view class='tabBar-right-content-bottom'>
        <label class='tabBar-right-content-label'>我的</label>
      </view>
    </view>
  </view>
</view>

tabbarStudy.wxss

/* 伪tabBar */
.tabBar {
  background-color: white;
  border-top: 1rpx solid #a9b7b7;
  color: "#a9b7b7";
  width: 100%;
  height: 100rpx;
  position: fixed;
  bottom: 0rpx;
  display: flex;
  flex-direction: row;
  /* justify-content: space-around; */
}

.tabBar-left {
  background-color: white;
  color: "#a9b7b7";
  width: 50%;
  height: 100rpx;
  display: flex;
  flex-direction: column;
}

.tabBar-left-content-top {
  background-color: white;
  color: "#a9b7b7";
  width: 100%;
  height: 70rpx;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  margin-top: 10rpx;
}

.tabBar-left-content-img {
  width: 50rpx;
  height: 50rpx;
}

.tabBar-left-content-bottom {
  background-color: white;
  color: "#a9b7b7";
  width: 100%;
  height: 30rpx;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

.tabBar-left-content-label {
  text-align: center;
  font-size: 25rpx;
  line-height: 25rpx;
  height: 25rpx;
  color: #a9b7b7;
}

.tabBar-right {
  background-color: white;
  color: "#a9b7b7";
  width: 50%;
  height: 100rpx;
  display: flex;
  flex-direction: column;
}

.tabBar-right-content-top {
  background-color: white;
  color: "#a9b7b7";
  width: 100%;
  height: 70rpx;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  margin-top: 10rpx;
}

.tabBar-right-content-img {
  width: 50rpx;
  height: 50rpx;
}

.tabBar-right-content-bottom {
  background-color: white;
  color: "#a9b7b7";
  width: 100%;
  height: 30rpx;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

.tabBar-right-content-label {
  text-align: center;
  font-size: 25rpx;
  line-height: 25rpx;
  height: 25rpx;
  color: #a9b7b7;
}

tabbarStudy.js

myCenter文件与上面的类似,不同之处

运行结果:

    

伪tabbar的不足:跳转的时候会出现闪烁 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值