返回顶部
a

auto-animate自动动画

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
2,076
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

auto-animate

AutoAnimate - 错误预防指南

包名: @formkit/auto-animate@0.9.0 (当前版本)
框架: React, Vue, Solid, Svelte, Preact
最后更新: 2026-01-21



SSR安全模式 (对Cloudflare Workers/Next.js至关重要)

tsx
// 使用客户端专用导入以防止SSR错误
import { useState, useEffect } from react;

export function useAutoAnimateSafe() {
const [parent, setParent] = useState(null);

useEffect(() => {
if (typeof window !== undefined && parent) {
import(@formkit/auto-animate).then(({ default: autoAnimate }) => {
autoAnimate(parent);
});
}
}, [parent]);

return [parent, setParent] as const;
}

为何重要: 防止问题#1 (SSR/Next.js导入错误)。AutoAnimate使用服务器上不可用的DOM API。



已知问题预防 (15个已记录错误)

此技能可预防 15 个已记录问题:

问题#1: SSR/Next.js导入错误

错误: 无法从非EcmaScript模块导入命名导出useEffect 来源: https://github.com/formkit/auto-animate/issues/55 原因: AutoAnimate使用服务器上不可用的DOM API 预防: 使用动态导入 (参见 templates/vite-ssr-safe.tsx)

问题#2: 条件性父元素渲染

错误: 当父元素是条件性渲染时动画不工作 来源: https://github.com/formkit/auto-animate/issues/8 原因: ref无法附加到不存在的元素 预防:

React模式:
tsx
// ❌ 错误
{showList &&

    ...
}

// ✅ 正确

    {showList && items.map(...)}

Vue.js模式:
vue


  • {{ item.text }}




  • {{ item.text }}

来源: React 问题#8, Vue 问题#193

问题#3: 缺少唯一键

错误: 项目动画不正确或闪烁 来源: 官方文档 原因: React无法追踪哪些项目发生了变化 预防: 始终使用唯一、稳定的键 (key={item.id})

问题#4: Flexbox宽度和抖动问题

错误: 元素直接跳转到宽度而非平滑动画,或容器在移除时抖动 来源: 官方文档, 问题#212 原因: flex-grow: 1等待周围内容,导致时序问题 预防: 对动画元素使用显式宽度而非flex-grow

tsx
// ❌ 错误 - 导致抖动


    {items.map(item => (
  • {item.text}

  • ))}

// ✅ 正确 - 固定尺寸


    {items.map(item => (
    key={item.id}
    style={{ minWidth: 200px, maxWidth: 200px }}
    >
    {item.text}

    ))}

维护者注: justin-schroeder确认flex容器需要固定尺寸

问题#5: 表格行显示问题

错误: 移除行时表格结构被破坏 来源: https://github.com/formkit/auto-animate/issues/7 原因: display: table-row与动画冲突 预防: 应用到而非单独的行,或使用基于div的布局

问题#6: Jest测试错误

错误: 找不到模块@formkit/auto-animate/react 来源: https://github.com/formkit/auto-animate/issues/29 原因: Jest未正确解析ESM导出 预防: 在jest.config.js中配置moduleNameMapper

问题#7: esbuild兼容性

错误: 包未导出路径. 来源: https://github.com/formkit/auto-animate/issues/36 原因: ESM/CommonJS条件不匹配 预防: 配置esbuild以正确处理ESM模块

问题#8: CSS定位副作用

错误: 添加AutoAnimate后布局被破坏 来源: 官方文档 原因: 父元素自动获得position: relative 预防: 在CSS中考虑位置变化或显式设置

问题#9: Vue/Nuxt注册错误

错误: 无法解析指令: auto-animate 来源: https://github.com/formkit/auto-animate/issues/43 原因: 插件未正确注册 预防: 在Vue/Nuxt配置中正确设置插件 (参见references/)

Nuxt 3注: 需要v0.8.2+ (2024年4月)。早期版本有Daniel Roe修复的ESM导入问题。参见问题#199

问题#10: Angular ESM问题

错误: 构建失败,提示仅ESM包 来源: https://github.com/formkit/auto-animate/issues/72 原因: CommonJS构建环境 预防: 为Angular包格式配置ng-packagr

问题#11: React 19 StrictMode双重调用错误

错误: 子元素动画在React 19 StrictMode中不工作 来源: https://github.com/formkit/auto-animate/issues/232 原因: StrictMode调用useEffect两次,触发autoAnimate初始化两次 预防: 使用ref追踪初始化

tsx
// ❌ 错误 - 在StrictMode中失效
const [parent] = useAutoAnimate();

// ✅ 正确 - 防止双重初始化
const [parent] = useAutoAnimate();
const initialized = useRef(false);

useEffect(() => {
if (initialized.current) return;
initialized.current = true;
}, []);

: React 19在开发模式下默认启用StrictMode。这影响所有React 19+项目。

问题#12: 视口外动画失效

错误: 列表在视口外时动画失效 来源: https://github.com/formkit/auto-animate/issues/222 原因: Chrome可能不为屏幕外元素运行动画API 预防: 在应用autoAnimate前确保父元素可见

tsx
const isInViewport = (element) => {
const rect = element.getBoundingClientRect();
return rect.top >= 0 && rect.bottom <= window.innerHeight;
};

useEffect(() => {
if (parent.current && isInViewport(parent.current)) {
autoAnimate(parent.current);
}
}, [parent]);

问题#13: 已删除元素覆盖现有内容

错误: 移除的项目在淡出期间覆盖其他项目 来源: https://github.com/formkit/auto-animate/issues/231 原因: 退出动画保持z-index,覆盖活动内容 预防: 添加显式z-index处理

tsx
// CSS解决方案

问题#14: 拖放期间无法禁用

错误: 调用enable(false)在拖放期间不阻止动画 来源: https://github.com/formkit/auto-animate/issues/215 原因: 在拖放过程中禁用不可靠 预防: 在拖放期间有条件地移除ref

tsx
const [isDragging, setIsDragging] = useState(false);
const [parent] = useAutoAnimate();

return (


    {/ 项目 /}

);

问题#15: CSS变换父元素位置错误

错误: 父元素变换后项目从错误位置开始动画 来源: https://github.com/formkit/auto-animate/issues/227 原因: 项目记住变换前的原始位置 预防: 延迟autoAnimate直到变换完成

tsx
useEffect(() => {

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 auto-animate-1776376097 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 auto-animate-1776376097 技能

通过命令行安装

skillhub install auto-animate-1776376097

下载

⬇ 下载 auto-animate v0.1.0(免费)

文件大小: 33.62 KB | 发布时间: 2026-4-17 15:12

v0.1.0 最新 2026-4-17 15:12
Auto-animate v0.1.0 — initial release with robust error prevention and animation patterns.

- Introduces zero-config animations for React, Vue, Solid, Svelte, and Preact using @formkit/auto-animate.
- Documents prevention for 15 common errors, including React 19 StrictMode bugs, SSR import issues, conditional parents, viewport problems, drag & drop conflicts, and CSS transform bugs.
- Provides SSR-safe usage patterns essential for serverless frameworks (e.g., Next.js, Cloudflare Workers).
- Includes framework-specific solutions, test/jest config guidance, and accessibility best practices for smooth, accessible transitions.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部