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>
相关推荐
To_OC28 分钟前
LC 207 课程表:刚学图论那会儿,我连这是拓扑排序都没看出来
javascript·算法·leetcode
To_OC37 分钟前
LC 208 实现 Trie 前缀树:曾被名字劝退,写完发现是送分题
javascript·算法·leetcode
天渺工作室1 小时前
实现一个adblock/adblock plus等浏览器广告拦截器检测插件
前端·javascript
阳光是sunny2 小时前
Vue 项目怎么做用户行为全链路监控?轻量插件方案详解
前端·面试·架构
ZhengEnCi2 小时前
Q04-Vite禁用CSS代码分割-解决生产环境样式加载顺序混乱问题
前端·vue.js·vite
九酒2 小时前
AI Agent 开发踩坑记:口播功能非得用 APP 原生实现吗?
前端·人工智能·agent
Jackson__3 小时前
做了一段时间的AI coding后,我终于搞清了 CLI 和 MCP 的区别
前端·agent·ai编程
IT_陈寒5 小时前
JavaScript项目实战经验分享
前端·人工智能·后端
用户47949283569156 小时前
6w star,GitHub 趋势第一的 Ponytail,这个agent插件到底在火什么
前端·后端
薛定喵的谔7 小时前
我开源了一个精致的 Next.js 博客模板:Skyplume
前端·前端框架·next.js