网站首页 > 知识剖析 正文
1. 基础动画
工具类 | 效果描述 |
animate-bounce | 上下弹跳效果(最常用) |
animate-pulse | 缓慢的透明度变化(呼吸感) |
animate-ping | 快速放大缩小并淡出(类似雷达扫描) |
animate-spin | 360° 旋转(加载指示器常用) |
2. 进入 / 退出动画
工具类 | 效果描述 |
animate-fade-in | 淡入效果 |
animate-fade-out | 淡出效果 |
animate-slide-in-from-top | 从顶部滑入 |
animate-slide-in-from-bottom | 从底部滑入 |
animate-slide-in-from-left | 从左侧滑入 |
animate-slide-in-from-right | 从右侧滑入 |
animate-zoom-in | 缩放进入 |
animate-zoom-out | 缩放退出 |
3. 强调动画
工具类 | 效果描述 |
animate-bounce-subtle | 轻微弹跳(幅度小) |
animate-shake | 左右抖动(错误提示常用) |
animate-swing | 左右摇摆 |
animate-tada | 快速缩放 + 摇摆(强调提示) |
animate-wobble | 不规则摇摆 |
使用示例
html
预览
<!-- 引入需先安装预设:npm install @unocss/preset-animations -->
<!-- 配置 unocss.config.ts 引入预设 -->
<!-- 弹跳效果 -->
<div class="animate-bounce p-4 bg-blue-50">弹跳元素</div>
<!-- 旋转加载指示器 -->
<div class="animate-spin w-8 h-8 border-4 border-blue-200 border-t-blue-500 rounded-full"></div>
<!-- 淡入效果 -->
<div class="animate-fade-in p-4 bg-green-50">淡入显示</div>
<!-- 抖动效果(错误提示) -->
<div class="animate-shake p-4 bg-red-50">输入错误</div>
如何使用内置动画
- 安装动画预设:
npm install @unocss/preset-animations
- 在 unocss.config.ts 中配置:
import { defineConfig } from 'unocss'
import animations from '@unocss/preset-animations'
export default defineConfig({
presets: [
animations(), // 引入动画预设
// 其他预设...
]
})
- 直接在 HTML 中使用上述工具类即可。
这些内置动画覆盖了大多数常见交互场景,且支持通过 duration-*(时长)、delay-*(延迟)等工具类进一步定制,例如 animate-bounce duration-500 delay-100 可调整动画时长和延迟时间。
- 上一篇: 炫酷的CSS3 loading加载动画,总有一款适合你
- 下一篇: HTML 二次函数图像动画展示
猜你喜欢
- 2025-08-06 12 个最佳 JavaScript 动画库,让您的 Web 页面动起来
- 2025-08-06 HTML 二次函数图像动画展示
- 2025-08-06 炫酷的CSS3 loading加载动画,总有一款适合你
- 08-0612 个最佳 JavaScript 动画库,让您的 Web 页面动起来
- 08-06HTML 二次函数图像动画展示
- 08-06UnoCSS 内置的动画
- 08-06炫酷的CSS3 loading加载动画,总有一款适合你
- 08-06想要开发更好的Python项目,代码质量是关键
- 08-06想要入门学好Python编程,先从这几本书开始
- 08-06甲方VS程序员精彩画面鉴赏
- 08-06后端语言性能排行,哪种语言最快,为什么?
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)