mcpField
M
motion-one

motion-one

github.com/dylantarre设计与 UI132548 次安装43 周前更新
代码仓库

关于 motion-one

这是一项使用 Motion One 实践迪士尼 12 条动画原则的设计技能,提供基于 Web Animations API 的示例,涵盖时间线、错开效果和滚动联动动画。

主要功能

  1. 01涵盖 12 条动画原则的示例
  2. 02单项动画与时间线
  3. 03错开效果与弹簧缓动
  4. 04滚动联动与视口内动画

适用场景

  1. 01为界面元素增添动感
  2. 02编排多个元素的动画顺序
  3. 03制作响应滚动的网页动画

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/dylantarre/animation-principles --skill motion-one

安装后在 Claude Code 中输入/motion-one确认已加载。

详细介绍

Motion One 动画原则

使用 Motion One 高性能的 Web Animations API 封装实现迪士尼的全部 12 条动画原则。

1. 挤压与拉伸

import { animate } from "motion";

animate(".ball",
  { scaleX: [1, 1.2, 1], scaleY: [1, 0.8, 1] },
  { duration: 0.3, easing: "ease-in-out" }
);

2. 预备动作

import { timeline } from "motion";

timeline([
  [".character", { y: 10, scaleY: 0.9 }, { duration: 0.2 }],
  [".character", { y: -200 }, { duration: 0.4, easing: "ease-out" }]
]);

3. 演出布局

animate(".background", { filter: "blur(3px)", opacity: 0.6 });
animate(".hero", { scale: 1.1 });

4. 连续动作与关键帧动作

animate(".element", {
  x: [0, 100, 200, 300],
  y: [0, -50, 0, -30]
}, { duration: 1 });

5. 跟随动作与重叠动作

timeline([
  [".body", { x: 200 }, { duration: 0.5 }],
  [".hair", { x: 200 }, { duration: 0.5, at: "-0.45" }],
  [".cape", { x: 200 }, { duration: 0.6, at: "-0.5" }]
]);

6. 慢入与慢出

animate(".element", { x: 300 }, {
  duration: 0.6,
  easing: [0.42, 0, 0.58, 1] // cubic-bezier ease-in-out
});
// Or: "ease-in", "ease-out", "ease-in-out"
// Or spring: { easing: spring({ stiffness: 100, damping: 15 }) }

7. 弧线运动

animate(".ball", {
  x: [0, 100, 200],
  y: [0, -100, 0]
}, { duration: 1, easing: "ease-in-out" });

// Or with offset path
animate(".element", {
  offsetDistance: ["0%", "100%"]
}, { duration: 1 });
// CSS: offset-path: path('M0,100 Q100,0 200,100');

8. 次要动作

const button = document.querySelector(".button");
button.addEventListener("mouseenter", () => {
  animate(button, { scale: 1.05 }, { duration: 0.2 });
  animate(".icon", { rotate: 15 }, { duration: 0.15 });
});

9. 时间节奏

import { spring } from "motion";

// Fast snap
animate(".fast", { x: 100 }, { duration: 0.15 });

// Spring physics
animate(".spring", { x: 100 }, {
  easing: spring({ stiffness: 300, damping: 20 })
});

// Slow dramatic
animate(".slow", { x: 100 }, { duration: 0.8, easing: "ease-out" });

10. 夸张

import { spring } from "motion";

animate(".element", { scale: 1.5, rotate: 720 }, {
  easing: spring({ stiffness: 200, damping: 10 }) // overshoot
});

11. 扎实绘制

animate(".box", {
  rotateX: 45,
  rotateY: 30
}, { duration: 0.5 });
// Set perspective in CSS: perspective: 1000px;

12. 吸引力

animate(".card", {
  scale: 1.02,
  boxShadow: "0 20px 40px rgba(0,0,0,0.2)"
}, { duration: 0.3, easing: "ease-out" });

错开动画

import { stagger } from "motion";

animate(".item",
  { opacity: [0, 1], y: [20, 0] },
  { delay: stagger(0.1) }
);

滚动动画

import { scroll, animate } from "motion";

scroll(
  animate(".parallax", { y: [0, 100] }),
  { target: document.querySelector(".container") }
);

进入视口时触发的动画

import { inView } from "motion";

inView(".section", ({ target }) => {
  animate(target, { opacity: 1, y: 0 }, { duration: 0.5 });
});

Motion One 的主要功能

  • animate() - 单个动画
  • timeline() - 使用 at 定位的动画序列
  • stagger() - 错开延迟
  • spring() - 基于物理的缓动
  • scroll() - 与滚动关联的动画
  • inView() - Intersection Observer 封装
  • 使用 Web Animations API(硬件加速)
  • 包体积小(约 3kb)

评论

支持 Markdown