当前位置: 首页 > news >正文

50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | Expanding Cards (展开式卡片)

📅 我们继续 50 个小项目挑战!—— Expanding Cards 组件

仓库地址:https://github.com/SunACong/50-vue-projects

项目预览地址:https://50-vue-projects.vercel.app/

在这里插入图片描述


✨ 组件目标

  • 一组横向排列的背景卡片
  • 点击卡片后,其展开至主要区域,其他卡片收缩
  • 显示当前卡片的标题,其他隐藏

🧱 技术实现点

  • Vue3 的响应式状态 ref
  • v-for 渲染卡片列表
  • TailwindCSS flex, transition, bg-cover, rounded, bg-[url] 等核心工具类
  • 条件样式绑定 :class

🔧 ExpandingCards.vue 组件实现

<template><div class="flex min-h-screen justify-center p-20"><divv-for="item in imagList":key="item.id"@click="current = item.id":class="['relative m-2 flex-1/12 cursor-pointer rounded-[4vw] bg-cover bg-center bg-no-repeat font-mono text-2xl text-white transition-all duration-500 ease-in-out',item.className,current === item.id ? 'flex-2/3' : 'flex-1/12',]"><h3:class="['absolute bottom-5 left-15 transition-all duration-500 ease-in-out',current === item.id ? 'opacity-100' : 'opacity-0',]">{{ item.title }}</h3></div></div>
</template><script setup>
import { ref } from 'vue'const current = ref(1)const imagList = [{id: 1,className:'bg-[url(https://images.unsplash.com/photo-1558979158-65a1eaa08691?auto=format&fit=crop&w=1350&q=80)]',title: 'Explore The World',},{id: 2,className:'bg-[url(https://images.unsplash.com/photo-1572276596237-5db2c3e16c5d?auto=format&fit=crop&w=1350&q=80)]',title: 'Wild Forest',},{id: 3,className:'bg-[url(https://images.unsplash.com/photo-1507525428034-b723cf961d3e?auto=format&fit=crop&w=1353&q=80)]',title: 'Sunny Beach',},{id: 4,className:'bg-[url(https://images.unsplash.com/photo-1551009175-8a68da93d5f9?auto=format&fit=crop&w=1351&q=80)]',title: 'City on Winter',},{id: 5,className:'bg-[url(https://images.unsplash.com/photo-1549880338-65ddcdfd017b?auto=format&fit=crop&w=1350&q=80)]',title: 'Mountains - Clouds',},
]
</script>

💡 TailwindCSS 样式重点讲解

类名功能描述
flex-1/12, flex-2/3自定义比例控制卡片展开宽度
bg-cover bg-center背景图片尺寸与居中展示
rounded-[4vw]圆角自定义为视口宽度
transition-all duration-500平滑过渡效果
opacity-0 / opacity-100控制标题显隐

🦌 常量定义 + 组件路由

constants/index.js添加组件预览常量

export const projectList = [{id: 1,title: 'Expanding Cards',image: 'https://50projects50days.com/img/projects-img/1-expanding-cards.png',link: 'ExpandingCards',}
]

router/index.jsrouter对象添加路由选项

{path: '/ExpandingCards',name: 'ExpandingCards',component: () => import('@/projects/ExpandingCards.vue')}

🚀 小结

这个组件展示了如何用非常少的代码和工具类实现炫酷 UI 效果。我们学会了:

  • 使用 v-for 构建动态组件结构
  • ref 管理当前状态
  • 动态绑定 class 实现动画和交互反馈
  • 熟练使用 TailwindCSS v4 的实用工具类,提升开发效率

📅 明日预告:Progress Steps!实现步骤引导组件。


🧠 每天进步一点点,50 天后惊艳所有人!

http://www.xdnf.cn/news/512227.html

相关文章:

  • AI预测3D新模型百十个定位预测+胆码预测+去和尾2025年5月18日第81弹
  • symfonos: 1靶场
  • 一个stm32工程从底层上都需要由哪些文件构成
  • 【ROS2】RViz2源码分析(九):RosClientAbstraction和RosNodeAbstraction的关系
  • Android 性能优化入门(二)—— 内存优化
  • MATLAB安装常见问题解决方案
  • C++23 放宽范围适配器以允许仅移动类型(P2494R2)
  • Java求职者面试:从Spring Boot到微服务的技术点解析
  • 什么是机器学习?
  • HiTool机顶盒刷机提示:网络下载TFTP超时,可能的原因如下
  • 原型链的详细解释及使用场景
  • ShenNiusModularity项目源码学习(26:ShenNius.Admin.Mvc项目分析-11)
  • JavaScript 中的 Window 对象详解
  • 气体放电管和TVS管之间加电感
  • 【Linux】利用多路转接epoll机制、ET模式,基于Reactor设计模式实现
  • AutoGPT-Agent简述版
  • java实现poi-ooxml导出Excel的功能
  • Graphics——基于.NET 的 CAD 图形预览技术研究与实现——CAD c#二次开发
  • 微软将于 8 月 11 日关闭 Bing Search API 服务
  • 服务器防文件上传手写waf
  • 系统性能不达标,如何提升用户体验?
  • IDEA - Windows IDEA 代码块展开与折叠(基础折叠操作、高级折叠操作)
  • 优先级队列(堆)
  • Vue-计算属性
  • Nordic 的RTC(Real-time counter)的介绍
  • 【GPT入门】第39课 OPENAI官方API调用方法
  • 螺旋矩阵--LeetCode
  • DB-MongoDB-00002--Workload Generator for MongoDB
  • ⭐️白嫖的阿里云认证⭐️ 第二弹【课时1:提示词(Prompt)技巧】for 「大模型Clouder认证:利用大模型提升内容生产能力」
  • 【NGINX】 -10 keepalived + nginx + httpd 实现的双机热备+ 负载均衡