Skip to content

Basic animations

Every animation in Bmotion is the same shape: a state to start from, a state to end at, and a transition describing how to get between them. Learn that shape here and the rest of the library - springs, gestures, keyframes, layout - is the same component with more parameters.

Initial and Animate

Initial is the state the element is painted in before it has ever animated; Animate is the state it heads for. The animation runs on mount and again whenever Animate changes, so switching a target in your own state is all it takes to animate - there is nothing to start or stop.

On mount
On every change · tap the box

Transforms, one property each

Every part of a transform is a property of its own. x and y move the element (a bare number is pixels), scale grows it evenly while scaleX and scaleY stretch one axis, rotate turns it (in degrees - rotateZ is the same turn under its 3-D name) and skewX / skewY lean it. Bmotion composes the ones you animate into the single transform the element gets, in a fixed order, so animating rotate never wipes out an x set somewhere else, and a hover that scales leaves a running rotation alone.

x: 40
y: -30
scale: 1.4
scaleX: 1.8
scaleY: 0.4
rotate: 135
skewX: 25
skewY: -20

CSS properties

Animation is not limited to transforms. Colors, borderRadius and boxShadow interpolate as values rather than snapping, and complex strings like filter interpolate too: between two values of the same shape, every number and embedded color inside them animates. Shapes that do not match snap to the target instead.

borderRadius + backgroundColor
filter: blur() saturate()
filter
boxShadow (multi-part)

3D transforms

perspective gives an element a vanishing point and rotateX / rotateY / z turn it in that space. They compose with the 2-D transforms into one transform value, so animating x and rotateY at once never has the two fighting over the property. originX / originY move the pivot everything turns about - 0 is the left/top edge, 1 the right/bottom.

rotateY · card flip
rotateX + rotateY · hover to tilt
originX: 0, originY: 1 · hinged at the bottom-left corner

Skipping the entrance

Initial="false" mounts the element already at its Animate target, with no enter animation - motion.dev's initial={false}. It is for content whose resting state is the point: a switch that should load showing the position it was saved in, a panel restored from the last visit. Only the mount is skipped; every later change of Animate animates as usual. Re-mount the two boxes and compare, then toggle them.

Initial="Bm.To(opacity: 0, scale: 0.4)" · plays its entrance
Initial="false" · mounts at rest

Timing per property

One Transition times every property a target changes. When they should move differently - the fade quick, the slide on a spring, the colour arriving last - give the transition a Properties map. Each entry names a property the way the engine does ("x", "opacity", "backgroundColor", …) and the transition to play it with. An entry replaces the base transition for that one property outright rather than merging with it, and every property the map doesn't name keeps the base transition.

one spring for x, opacity and colour
Properties · a quick fade, a late colour

delay holds an animation back by that many seconds, on any transition. WithDelay returns a copy of a configured transition with a different delay, which is how one spring is reused across a row of elements without mutating the shared instance - each box below gets the same spring, offset by its index.

Composing targets

A target is a value, so it can be built from parts. + layers one target over another (a.With(b) is the same thing as a method): every property the right-hand side sets wins, every one it leaves unset keeps the left-hand value, and css / cssVars merge key by key. Neither side is changed, so a set of named building blocks can be combined freely. Below, the resting card is the base, and each switch layers one more block on top of it.

_rest

Knowing when it ran

OnAnimationStart fires as an Animate (or variant) change starts to play and OnAnimationComplete when it finishes; both hand you the target that played, so one handler can tell its states apart. Complete means finished: press the button again while the box is still moving and the run it interrupts reports no completion - only the run that lands does. That makes it the hook for work that must wait for the motion, such as moving focus once a panel has opened. An entrance played from prerendered HTML (see Getting started) finished before the runtime arrived, so it reports neither.

No events yet.
Bmotion 0 el · 0 active ▸
An unhandled error has occurred. Reload 🗙