tabbar导航栏动画 自定义

复制代码
 <div class="box">
    <div class="container" id="my">
      <div class="item" v-for="(el,index) in item" :key="index" @click="isNum=index" :class="isNum==index?'active':''">
        <img :src="el.imge" alt="">
        <p class="text">{{el.name}}</p>
      </div>

      <div class="plus"></div>
    </div>
  </div>

 data() {
    return {
      isNum: 1,
      item: [
        { imge: require('../assets/20.png'), name: '首页' },
        { imge: require('../assets/30.png'), name: '首页' },
        { imge: require('../assets/40.png'), name: '首页' },
        { imge: require('../assets/50.png'), name: '首页' },
      ]
    }
  }

<style>
* {
  margin: 0;
  padding: 0;
}


.container {
  width: 400px;
  height: 70px;
  background-color: blue;
  display: flex;
  align-items: center;
  justify-content: space-around;
  text-align: center;
  color: #fff;
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 100%);
}

.container .item img {
  width: 20px;
  height: 20px;
}

.container .item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.plus {
  position: absolute;
  left: 10px;
  top: -58%;
  background-color: rgb(231, 209, 7);
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 6px solid #fff;
  /* 过渡 */
  transition: 0.5s;

}

/* 圆弧 */
.plus::before {
  content: "";
  position: absolute;
  /* background: blue; */
  border-top-right-radius: 20px;
  width: 20px;
  height: 20px;
  top: 50%;
  left: -20px;
  box-shadow: 0 -10px 0 0 #fff;
}
.plus::after {
  content: "";
  position: absolute;
  border-top-left-radius: 20px;
  width: 20px;
  height: 20px;
  top: 50%;
  right: -20px;
  box-shadow: 0 -10px 0 0 #fff;
}

/* 选中样式 未选中样式 */
/* 未选中样式  文字 位移 不显示 */
.container .item img {
  position: absolute;
  font-size: 24px;
  /* 过渡 */
  transition: 0.5s;

}

.text {
  opacity: 0;
  font-weight: 600;
  transform: translateY(20px);
  /* 过渡 */
  transition: 0.5s; 
}

/* 选中样式 */
.item.active img {
  transform: translateY(-30px);
  z-index:99;
}

.item.active .text {
  opacity: 1;
  transform: translateY(15px);
}

.item:nth-child(1).active ~ .plus {
  transform: translateX(calc(100px * 0));
}

.item:nth-child(2).active ~ .plus {
  transform: translateX(calc(100px * 1));
}

.item:nth-child(3).active ~ .plus {
  transform: translateX(calc(100px * 2));
}

.item:nth-child(4).active ~ .plus {
  transform: translateX(calc(100px * 3));
}
相关推荐
程序员黑豆32 分钟前
鸿蒙应用开发:V1与V2版本数据持久化实战教程
前端·harmonyos
小月土星4 小时前
React Router 前端路由深度解析:从传统后端路由到现代 SPA 的完整演进
前端
程序员黑豆4 小时前
鸿蒙开发 Navigation 路由教程:从入门到实战
前端·harmonyos
烬羽6 小时前
React Router v7 完全指南:一个 Demo 吃透前端路由
javascript·react.js·前端框架
烬羽6 小时前
从"整个页面刷新"到"丝滑切换":手写一个 HashRouter 彻底搞懂前端路由
javascript·前端框架·全栈
用户938515635077 小时前
从零理解 React Router v6:每一个 API 都是怎么工作的
前端·javascript·全栈
用户059540174469 小时前
Redis缓存回滚踩坑实录:一个配置失误,让我在凌晨3点丢了3000条数据
前端·css
kyriewen9 小时前
别再这样写条件渲染了——你的React组件里藏着这5种定时炸弹
前端·javascript·react.js
IT_陈寒10 小时前
Redis缓存击穿把我坑惨了,原来这样设过期时间才靠谱
前端·人工智能·后端
用户9385156350710 小时前
从"坐电梯"到"前端路由"——深入理解 Hash 路由原理
前端·typescript·全栈