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 { w } from "@wardic/solid/unstable/v2"
/** 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/solid1.tsx
import { w } from "@wardic/solid"
/** 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/motion.tsx
import { motion } from "motion/react"
/** A card that rises into place as it mounts, and lifts under the pointer. */
export default function Enter() {
return (
<motion.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
</motion.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.