评论

小程序 view 加样式 实现 Tabbar 样式组件,类似微信公众号二级菜单栏

小程序实现 tabbar 类似微信公众号二级菜单效果

微信小程序代码片段: https://developers.weixin.qq.com/s/yNkjRYmF8f0R

开发钉钉小程序的时候,需要用到 Tabbar 类似公众号的样式组件,试着去写个简单的Demo,写完用微信小程序开发工具复用预览效果,发现可共用。

<view class="m-tab-bar">
      <view class="tab-bar__item ">
        <view class="tab-bar-item__content ">
          首页
        </view>
      </view>
      <view class="tab-bar__item ">
        <view class="tab-bar-item__content ">
          收藏
        </view>
      </view>
      <view class="tab-bar__item  ">
        <view class="tab-bar-item__content tab-bar-item__content--checked">
          喜欢
        </view>
        <view class="tab-bar-item__spread">
          <view class="tab-bar-item__spread-item">
            <view class="tab-bar-item__spread-item-text">基本信息</view>
          </view>
          <view class="tab-bar-item__spread-item">
            <view class="tab-bar-item__spread-item-split"></view>
            <view class="tab-bar-item__spread-item-text">个人主页</view>
          </view>
          <view class="tab-bar-item__spread-item">
            <view class="tab-bar-item__spread-item-split"></view>
            <view class="tab-bar-item__spread-item-text">设置</view>
          </view>
        </view>
      </view>
    </view>




.m-tab-bar {
  position: relative;
  width100%;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  background-color#fff;
}


.m-tab-bar .tab-bar__item {
  height40px;
  flex1;
  padding0 12px;
  margin8px 0;
  position: relative;


}


.m-tab-bar .tab-bar__item .tab-bar-item__content {
  text-align: center;
  align-items: center;
  justify-content: center;
  display: flex;
  background-color#fff;
  width100%;
  height100%;
  position: relative;
}



.m-tab-bar .tab-bar__item .tab-bar-item__spread {
  position: absolute;
  top0;
  left7%;
  width86%;
  background-color#ffffff;
  -webkit-transformtranslate3d(0, calc(-100% - 16px), 0);
  transformtranslate3d(0, calc(-100% - 16px), 0);
  z-index1;
  border-radius6px;
  colorrgba(000, .9);
  -webkit-box-shadow0 6px 30px 5px rgba(000, .05), 0 16px 24px 2px rgba(000, .04), 0 8px 10px -5px rgba(000, .08);
  box-shadow0 6px 30px 5px rgba(000, .05), 0 16px 24px 2px rgba(000, .04), 0 8px 10px -5px rgba(000, .08);
}




.m-tab-bar .tab-bar__item .tab-bar-item__spread .tab-bar-item__spread-item {
  width100%;
  height48px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: start;
  -ms-flex-pack: start;
  justify-content: flex-start;
  position: relative;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}


.tab-bar-item__content--checked {
  color#3086ff;
  font-weight600;
}


.m-tab-bar .tab-bar__item .tab-bar-item__spread .tab-bar-item__spread-item .tab-bar-item__spread-item-text {
  padding-top12px;
}



.m-tab-bar .tab-bar__item .tab-bar-item__spread .tab-bar-item__spread-item .tab-bar-item__spread-item-split {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  content" ";
  pointer-events: none;
  background-color#e7e7e7;
  width80%;
  height1px;
  -webkit-transformtranslateY(.5);
  transformtranslateY(.5);
}



.tab-bar-item__spread:before {
  display: block;
  content"";
  position: absolute;
  bottom0;
  left50%;
  width0;
  height0;
  border8px solid transparent;
  border-top8px solid #fff;
  -webkit-transformtranslate3d(-50%16px0);
  transformtranslate3d(-50%16px0);
}


最后一次编辑于  06-17  
点赞 0
收藏
评论
登录 后发表内容