tab切换,实现圆角效果

31 篇文章 0 订阅

准备张圆角图片

3种样式

第一个tab样式

  
.active {
        background-color: #fff;
        position: relative;
        border-top-left-radius: 0.2rem;
        color: #a55b16;
        font-weight: 600;
        &::after {
          content: "";
          width: 0.25rem;
          height: 0.25rem;
          position: absolute;
          bottom: -13px;
          right: 0;
          background: url("../../assets/detail/8.png") no-repeat;
          background-size: cover;
        }
      }
      

 中间的tab样式

.active1 {
        background-color: #fff;
        position: relative;
        color: #a55b16;
        font-weight: 600;
        &::after,
        &::before {
          content: "";
          width: 0.25rem;
          height: 0.25rem;
          position: absolute;
          right: 0;
        }
        &::after {
          bottom: -13px;
          background: url("../../assets/detail/8.png") no-repeat;
          background-size: cover;
        }
        &::before {
          top: -13px;
          background: url("../../assets/detail/9.png") no-repeat;
          background-size: cover;
        }
      }
     

最后一个tab样式 

 .active2 {
        background-color: #fff;
        position: relative;
        color: #a55b16;
        font-weight: 600;
        &::after {
          content: "";
          width: 0.25rem;
          height: 0.25rem;
          position: absolute;
          top: -13px;
          right: 0;
          background: url("../../assets/detail/9.png") no-repeat;
          background-size: cover;
        }
      }

点击切换添加样式 

添加:节点.classList.add("类名");

删除:节点.classList.remove("类名");

  const getIndex = (i: number) => {
      //点击获取当前项
      const a = document.getElementsByClassName('aa')[i]
      //获取整个列表数组
      const aList = document.getElementsByClassName('aa')
      if (i === 0) {
        a.classList.add('active')
        for (let j = 0; j < aList.length; j++) {
          aList[j].classList.remove('active1', 'active2')
        }
      } else if (i === state.sliderList.length - 1) {
        a.classList.add('active2')
        for (let j = 0; j < aList.length; j++) {
          aList[j].classList.remove('active1', 'active')
        }
      } else  {
        a.classList.add('active1')
        for (let j = 0; j < aList.length; j++) {
          if (j !== i) {
            aList[j].classList.remove('active1')
          }
          aList[j].classList.remove('active', 'active2')
        }
      }
    }

感觉这么做麻烦,希望大家能提出更好的建议 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值