(uniapp)简单带动画的tab切换效果

效果图

在这里插入图片描述

代码

<template>
  <view class="tabBox">
    <view :style="{transform: `translateX(${translateX})`}" class="whiteBox"></view>
    <view @click="changeTab(k)" class="itemBox" v-for="(v,k) in tabList" :key="k">{{ v }}</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
      tabList: ['TAB1', 'TAB2', 'TAB3', 'TAB4'],
    };
  },
  computed: {
    translateX() {
      return this.currentIndex * 100 + '%';
    }
  },
  methods: {
    changeTab(index) {
      this.currentIndex = index;
    }
  }
}
</script>

<style lang="scss" scoped>
.tabBox {
  display: flex;
  position: relative;
  background-color: #04f6f6;

  .whiteBox {
    position: absolute;
    width: 25%;//这里的宽度根据自己tab来设定
    height: 100rpx;
    background: white;
    transition: transform 0.3s;
    z-index: 0;
  }

  .itemBox {
    width: 25%;
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    z-index: 1;
  }

}
</style>

相关推荐

  1. Vue实现table左右切换平滑过渡效果

    2024-06-06 22:34:05       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-06 22:34:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-06 22:34:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-06 22:34:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-06 22:34:05       18 阅读

热门阅读

  1. Python Django 5 Web应用开发实战

    2024-06-06 22:34:05       9 阅读
  2. qnx 查看cpu使用

    2024-06-06 22:34:05       7 阅读
  3. Nginx替代软件

    2024-06-06 22:34:05       9 阅读
  4. SpringMVC:向三大域对象存数据

    2024-06-06 22:34:05       10 阅读
  5. Excel的VLOOKUP函数的用法

    2024-06-06 22:34:05       6 阅读
  6. C# virtual 关键字

    2024-06-06 22:34:05       8 阅读
  7. SAP ABAP下拉筛选框实现

    2024-06-06 22:34:05       8 阅读
  8. c++学习笔记“类和对象”;友元函数

    2024-06-06 22:34:05       8 阅读
  9. map和set

    map和set

    2024-06-06 22:34:05      9 阅读
  10. GPT发展途径

    2024-06-06 22:34:05       9 阅读