css 巧用 ::after 实现 tab 切换动效

2023-12-13 03:37:12

在这里插入图片描述

<template>
  <div class="container">
    <div class="tabBox">
      <div
        v-for="(item, index) in tabList"
        :key="index"
        class="tab"
        :class="{ active: index === activeIndex }"
        @click="activeIndex = index"
      >
        {{ item.label }}
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activeIndex: 0,
      tabList: [
        {
          label: "精选好物",
        },
        {
          label: "炫酷动漫",
        },
        {
          label: "贺岁影院",
        },
      ],
    };
  },
};
</script>

<style lang="scss" scoped>
.tabBox {
  display: flex;
  justify-content: space-evenly;
  height: 100px;
  line-height: 90px;
  margin: 0 20px;
  font-size: 28px;
  border-radius: 10px;
  box-shadow: 0 4px 5px rgba(200, 200, 200, 0.3);
  color: #333;
  background-color: #fff;
  position: relative;
  z-index: 9;
  .tab {
    margin: 0 20px;
    position: relative;
    cursor: pointer;
  }
  .active {
    &::after {
      content: "";
      width: 40px;
      height: 4px;
      transform: translate(-50%);
      background-color: #27ba9b;
      position: absolute;
      left: 50%;
      bottom: 24px;
    }
  }
}
.container {
  margin: 30px;
}
</style>

文章来源:https://blog.csdn.net/weixin_41192489/article/details/134881852
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。