--- title: React 动效组件展示 description: 展示 NovaBlog 中可用的 React 动效 HTML 组件,包括悬浮卡片、打字机效果、翻转卡片和粒子背景 pubDate: 2024-01-20 author: NovaBlog tags: [React, 动效, 组件, 教程] category: 教程 heroImage: '/images/hello-world.jpg' --- import AnimatedCard from '../../components/react/AnimatedCard'; import TypewriterText from '../../components/react/TypewriterText'; import FlipCard from '../../components/react/FlipCard'; import ParticleBackground from '../../components/react/ParticleBackground'; # React 动效组件展示 NovaBlog 支持在 MDX 中直接使用 React 组件,实现丰富的交互动效。本文展示了一些内置的动效组件示例。 ## 🎴 悬浮卡片 (AnimatedCard) 鼠标悬停时卡片会浮起并放大,配合阴影效果增强立体感。
## ⌨️ 打字机效果 (TypewriterText) 模拟打字机的逐字显示效果,支持循环播放。
### 使用方式 ```tsx ``` ## 🔄 翻转卡片 (FlipCard) 点击卡片实现 3D 翻转效果,适合展示正反两面内容。
### 使用方式 ```tsx 正面内容} backContent={
背面内容
} frontColor="#3b82f6" backColor="#10b981" client:load /> ``` ## ✨ 粒子背景 (ParticleBackground) 基于 Canvas 的粒子动画背景,粒子之间会自动连线,营造科技感。 ### 自定义内容

🎉 自定义内容

可以在粒子背景上放置任意内容

## 📝 如何在文章中使用 ### 1. 导入组件 在文章顶部添加 import 语句: ```mdx import AnimatedCard from '../../components/react/AnimatedCard'; ``` ### 2. 使用组件 ```mdx ``` ### 3. client 指令说明 | 指令 | 说明 | |------|------| | `client:load` | 页面加载时立即激活组件 | | `client:visible` | 组件进入视口时激活 | | `client:idle` | 浏览器空闲时激活 | | `client:media="(min-width: 768px)"` | 满足媒体查询时激活 | ## 🎨 创建自定义组件 你可以在 `src/components/react/` 目录下创建自己的 React 组件: ```tsx // src/components/react/MyComponent.tsx import { useState } from 'react'; interface MyComponentProps { title: string; } export default function MyComponent({ title }: MyComponentProps) { const [count, setCount] = useState(0); return (

{title}

); } ``` 然后在文章中使用: ```mdx import MyComponent from '../../components/react/MyComponent'; ``` --- ## 总结 NovaBlog 提供了灵活的组件系统,让你可以在 Markdown 中嵌入丰富的交互内容。通过 React 组件,你可以实现: - 🎴 **视觉效果**:悬浮、翻转、渐变等动画 - ⌨️ **动态文字**:打字机、滚动、闪烁效果 - ✨ **背景特效**:粒子、波浪、光效 - 🎮 **交互功能**:计数器、表单、游戏 快去尝试创建属于你自己的动效组件吧! 🚀