viewmotion

motion()

viewmotion

Returns an object of HTML attributes (data-motion + style) that can be spread onto any element. Designed for Astro and SSR frameworks.

Signature

function motion(config: MotionConfig): Record<string, string>;

Options

PropertyTypeDefaultDescription
presetstringAnimation preset name (required)
delaynumber0Delay before animation starts (ms)
durationnumber600Animation duration (ms)

Return value

Returns a plain object with the data-motion attribute ready to be spread:

// Returns:
{
  "data-motion": '{"preset":"fade-up","delay":200}'
}

Usage in Astro

---
import { motion } from "viewmotion";
---

<h1 {...motion({ preset: "fade-up", delay: 200 })}>Hello world</h1>
<p {...motion({ preset: "fade-up", duration: 800 })}>Longer animation</p>