开发中间带有+号和悬浮按钮的底部选项卡

1、新建一个uniapp项目,选择模板

2、 创建好之后,用微信开发者工具打开,默认点击【发布】,悬浮框出现,但在实际项目当中,不用每次点击【发布】tab都显示悬浮框,针对上述问题,做如下优化:

  • 第一次切换到【发布】tab时,默认不显示悬浮框,页面只显示图标,且背景为白色;
  • 再次点击【发布】时,悬浮框出现,背景变灰色;
  • 点击灰色区域,悬浮框消失
  • 来回点击【发布】,悬浮框显示与隐藏,同时页面背景色跟着变化

效果图如下:

3、修改原模板的tabbar-3.vue页面,其余保持不变

<template>
  <view class="content" :class="{'active':active}" @click="onCancleActive">
    <!-- 1 图 -->
    <image class="logo active" src="../../../static/logo.png" mode="aspectFit"></image>
    <!-- 2 悬浮按钮 -->
    <view class="tabbar-box-wrap" v-show="active">
      <view class="tabbar-box">
        <!-- 2.1 发图文 -->
        <view class="tabbar-box-item" @click.stop="goToPage('/pages/tabbar-3-detial/tabbar-3-release/tabbar-3-release')">
          <image class="box-image" src="../../../static/img/release.png" mode="aspectFit"></image>
          <text class="explain">发图文</text>
        </view>
        <!-- 2.2 发视频 -->
        <view class="tabbar-box-item" @click.stop="goToPage('/pages/tabbar-3-detial/tabbar-3-video/tabbar-3-video')">
          <image class="box-image" src="../../../static/img/video.png" mode="aspectFit"></image>
          <text class="explain">发视频</text>
        </view>
        <!-- 2.3 提问 -->
        <view class="tabbar-box-item" @click.stop="goToPage('/pages/tabbar-3-detial/tabbar-3-qa/tabbar-3-qa')">
          <image class="box-image" src="../../../static/img/qa.png" mode="aspectFit"></image>
          <text class="explain">提问</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        active: true
      };
    },
    onShow() {
      console.log("1-onShow");
      // #ifdef MP-WEIXIN  
      this.active = true;
      // #endif

      // #ifdef H5
      this.active = false;
      // #endif

    },
    onHide() {
      this.active = false;
    },
    onTabItemTap(obj) {
      console.log("2-onTabItemTap");
      if (obj) {
        this.active = !this.active;
      }
    },
    methods: {
      onCancleActive() {
        this.active = false;
      },
      goToPage(url) {
        if (!url) return;
        uni.navigateTo({
          url
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;

    /* #ifdef H5 */
    height: calc(100vh - var(--window-bottom) - var(--window-top));
    /* #endif */

    /* #ifndef H5 */
    height: 100vh;
    /* #endif */
    background: #fff;

    &.active {
      background: #999;
    }

    // 渐变效果
    // transition: opacity 0.3s;
    // opacity: 0;
    // &.active {
    // 	opacity: 1;
    // }

    .logo {
      position: relative;
      margin-top: -400upx;
      width: 200upx;
      height: 200upx;
      // z-index: -1;
      // opacity: 0;
      // transition: opacity 0.3s;
      // &.active {
      // 	opacity: 1;
      // }
    }
  }

  .tabbar-box-wrap {
    position: absolute;
    width: 100%;
    padding: 50upx;
    box-sizing: border-box;
    bottom: 0;
    left: 0;

    .tabbar-box {
      position: relative;
      display: flex;
      width: 100%;
      background: #fff;
      border-radius: 20upx;
      padding: 15upx 20upx;
      box-sizing: border-box;
      z-index: 2;
      box-shadow: 0px 2px 5px 2px rgba(0, 0, 0, 0.1);

      &:after {
        content: '';
        position: absolute;
        bottom: -16upx;
        left: 0;
        right: 0;
        margin: auto;
        width: 50upx;
        height: 50upx;
        transform: rotate(45deg);
        background: #fff;
        z-index: 1;
        box-shadow: 2px 2px 5px 1px rgba(0, 0, 0, 0.1);
        border-radius: 2px;
      }

      &:before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: #ffffff;
        border-radius: 20upx;
        z-index: 2;
      }

      .tabbar-box-item {
        width: 100%;
        z-index: 3;
        margin: 10upx;
        color: $uni-color-subtitle;
        text-align: center;
        font-size: $uni-font-size-base;

        .box-image {
          width: 100%;
          height: $uni-img-size-lg;
        }
      }
    }
  }
</style>

注意:微信小程序和H5页面onTabItemTap()和onShow()执行顺序相反,需要做处理

onShow() {
      console.log("1-onShow");
      // #ifdef MP-WEIXIN  
      this.active = true;
      // #endif

      // #ifdef H5
      this.active = false;
      // #endif

},

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

佛佛ง

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

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

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

打赏作者

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

抵扣说明:

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

余额充值