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>
相关推荐
东东5161 天前
基于ssm的网上房屋中介管理系统vue
前端·javascript·vue.js
harrain1 天前
什么!vue3.4开始,v-model不能用在prop上
前端·javascript·vue.js
阿蒙Amon1 天前
TypeScript学习-第7章:泛型(Generic)
javascript·学习·typescript
睡美人的小仙女1271 天前
Threejs加载环境贴图报错Bad File Format: bad initial token
开发语言·javascript·redis
fanruitian1 天前
uniapp android开发 测试板本与发行版本
前端·javascript·uni-app
rayufo1 天前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
RANCE_atttackkk1 天前
[Java]实现使用邮箱找回密码的功能
java·开发语言·前端·spring boot·intellij-idea·idea
摘星编程1 天前
React Native + OpenHarmony:Timeline垂直时间轴
javascript·react native·react.js
2501_944525541 天前
Flutter for OpenHarmony 个人理财管理App实战 - 支出分析页面
android·开发语言·前端·javascript·flutter
jin1233221 天前
React Native鸿蒙跨平台完成剧本杀组队详情页面,可以复用桌游、团建、赛事等各类组队详情页开发
javascript·react native·react.js·ecmascript·harmonyos