Skip to content

Motion 尽可能兼容了 Web Animations API 并做了很多增强,例如支持 spring 动画,详见:Improvements to Web Animations API

ts
import { animate } from 'motion';

// @see https://motion.dev/docs/animate#transforms
await animate(rect, { angle: 360 }, { duration: 2 });
await animate(rect, { opacity: [0, 1] }, { duration: 1.5 });
await animate(
    rect,
    { scaleX: [1, 0], scaleY: [1, 0] },
    { duration: 1.5, repeat: Infinity, repeatType: 'reverse' },
);

但和 Web Animations API 还是有一些区别,例如:

  • durationdelay使用秒而非毫秒
  • iterations -> repeat
  • direction -> repeatType

Released under the MIT License.