Animate an element
A w.* element takes Motion's props. initial is where it starts, animate where it goes, and transition how it gets there. Change animate, and it moves from wherever it is to the new target.
enter/solid2.tsx
import { createWard } from "@wardic/solid/hooks"
/** A card that rises into place as it mounts, and lifts under the pointer. */
export default function Enter() {
const card = createWard({
initial: { opacity: 0, y: 24 },
animate: { opacity: 1, y: 0 },
whileHover: { y: -4, scale: 1.02 },
transition: { type: "spring", stiffness: 260, damping: 22 },
})
return (
<div class="sample-card" {...card}>
Hello, Wardic
</div>
)
}enter/solid1.tsx
import { w } from "~/lib/wardic.ts"
/** A card that rises into place as it mounts, and lifts under the pointer. */
export default function Enter() {
return (
<w.div
class="sample-card"
initial={{ opacity: 0, y: 24 }}
animate={{ opacity: 1, y: 0 }}
whileHover={{ y: -4, scale: 1.02 }}
transition={{ type: "spring", stiffness: 260, damping: 22 }}
>
Hello, Wardic
</w.div>
)
}enter/foldkit.ts
import type { Html, HtmlBuilder } from "foldkit/html"
import { wardic } from "~/lib/wardic.ts"
/** A card that rises into place as it mounts, and lifts under the pointer. */
export const view = <Message,>(h: HtmlBuilder<Message>): Html => {
const w = wardic.html(h)
return w.div(
[
h.Class("sample-card"),
w.Initial({ opacity: 0, y: 24 }),
w.Animate({ opacity: 1, y: 0 }),
w.WhileHover({ y: -4, scale: 1.02 }),
w.Transition({ type: "spring", stiffness: 260, damping: 22 }),
],
["Hello, Wardic"],
)
}enter/motion.tsx
import * as m from "motion/react-m"
/** A card that rises into place as it mounts, and lifts under the pointer. */
export default function Enter() {
return (
<m.div
className="sample-card"
initial={{ opacity: 0, y: 24 }}
animate={{ opacity: 1, y: 0 }}
whileHover={{ y: -4, scale: 1.02 }}
transition={{ type: "spring", stiffness: 260, damping: 22 }}
>
Hello, Wardic
</m.div>
)
}Where it starts
On a server-rendered page, the element arrives in the HTML already at initial, so it never flashes at its target first. Its entrance plays from the first paint, before the JavaScript has loaded, and the client takes it over mid-flight.
How it moves
transition takes a spring (stiffness, damping, mass, or a duration with a bounce), a tween (duration and ease), or inertia. Without one, a key gets Motion's default for it: a spring for position and scale, a tween for opacity and colour.
In the storefront
The storefront's examples that show it, live and with their code:
- Stock that fills in as it arrives: Each piece's stock meter fills in once the store's count arrives, and says when it has settled. Switch to after the delivery and they fill up from where they are. (on Foldkit)
- Glaze test tiles that turn over: Tap a glaze's test tile and it turns over to show its recipe, each tile in a depth of its own, wherever it sits on the wall.