CSS动效

1. 卡片切换动画

html 复制代码
<template>
  <div class="page">
    <h1>卡片切换动画</h1>
    <van-button type="primary" @click="handleSwitch">切换</van-button>
    <div class="container">
      <div class="list" :class="{ enter: activeListIndex === 1, leave: activeListIndex !== 1 }">
        <div v-for="item in list1" :key="item.value" class="card">{{ item.label }}</div>
      </div>
      <div class="list" :class="{ enter: activeListIndex === 2, leave: activeListIndex !== 2 }">
        <div v-for="item in list2" :key="item.value" class="card">{{ item.label }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const list1 = ref([
  {
    label: '卡片1',
    value: 1
  },
  {
    label: '卡片2',
    value: 2
  },
  {
    label: '卡片3',
    value: 3
  }
])

const list2 = ref([
  {
    label: 'card4',
    value: 4
  },
  {
    label: 'card5',
    value: 5
  },
  {
    label: 'card6',
    value: 6
  }
])

const activeListIndex = ref(1)
function handleSwitch() {
  activeListIndex.value = activeListIndex.value === 1 ? 2 : 1
}
</script>

<style lang="scss" scoped>
.page {
  width: 100%;
  height: 100%;
  padding: 10px;
  color: #ffffff;
  background-color: black;

  .container {
    width: 100%;
    height: 80px;
    border: 1px solid #ccc;
    margin-top: 10px;
    padding: 0 10px;
    position: relative;
    overflow: hidden;

    .list {
      width: 100%;
      height: 100%;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      overflow-x: auto;
      gap: 10px;
      transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
      backface-visibility: hidden;
      position: absolute;

      &.enter {
        opacity: 1;
        transform: translateY(0);
        z-index: 2;
      }

      &.leave {
        opacity: 0;
        transform: translateY(100%);
        z-index: 1;
      }
    }

    .card {
      width: 60px;
      height: 60px;
      background-color: #404040;
      border-radius: 6rem;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>
相关推荐
烛阴2 小时前
3D字体TextGeometry
前端·webgl·three.js
桜吹雪2 小时前
markstream-vue实战踩坑笔记
前端
南村群童欺我老无力.2 小时前
Flutter应用鸿蒙迁移实战:性能优化与渐进式迁移指南
javascript·flutter·ci/cd·华为·性能优化·typescript·harmonyos
C_心欲无痕2 小时前
nginx - 实现域名跳转的几种方式
运维·前端·nginx
花哥码天下3 小时前
恢复网站console.log的脚本
前端·javascript·vue.js
LawrenceLan3 小时前
Flutter 零基础入门(十二):枚举(enum)与状态管理的第一步
开发语言·前端·flutter·dart
Zoey的笔记本3 小时前
「支持ISO27001的GTD协作平台」数据生命周期管理方案与加密通信协议
java·前端·数据库
奔跑的呱呱牛3 小时前
geojson-to-wkt 坐标格式转换
javascript·arcgis
C_心欲无痕3 小时前
Docker 本地部署 CSR 前端项目完整指南
前端·docker·容器