Method Motion
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
Motion(string?, string?, string?, StyleTransitionConfig?, float?, EasingMode?, float?, Action?, VNode?[]?, FiberElementProps?, FiberEventBinding[]?, Func<VisualElement, Action>?, string?, string?, string?, Type?, IReadOnlyDictionary<string, MotionVariant>?, string?, string?, string?, string?, bool)
Element targeted by an animation.
Used inside AnimatePresence; toggles CSS classes on mount / unmount according to transition.
The one exception is a variant initial/animate pair (see
initial), which plays its mount enter on any Motion, standalone or not.
When transition is null, StyleTransition.Fade is applied as the default.
duration / easing can override individual fields of the
transition preset (e.g. setting only the duration while keeping the preset's other fields).
To disable animation entirely (immediate mount / unmount), pass transition: StyleTransitionConfig.None.
Note: when DurationSec is 0 (including StyleTransitionConfig.None), delay is ignored
and completion is immediate, except for a Spring with no RepeatDelaySec, which is instant
but waits out delay before it lands (see motion.md).
public static MotionNode Motion(string? className = null, string? key = null, string? name = null, StyleTransitionConfig? transition = null, float? duration = null, EasingMode? easing = null, float? delay = null, Action? onEnterComplete = null, VNode?[]? children = null, FiberElementProps? props = null, FiberEventBinding[]? events = null, Func<VisualElement, Action>? refCallback = null, string? whileHoverClass = null, string? whileTapClass = null, string? whileFocusClass = null, Type? elementType = null, IReadOnlyDictionary<string, MotionVariant>? variants = null, string? animate = null, string? initial = null, string? exit = null, string? layoutId = null, bool enterOnMount = true)
Parameters
classNamestringCSS-like utility class string. Multiple classes separated by spaces.
keystringKey used to disambiguate siblings at the same position.
namestringElement name assigned to UnityEngine.UIElements.VisualElement.name for query/debug.
transitionStyleTransitionConfigTransition preset; defaults to
StyleTransition.Fadewhen null. Avariantsentry naming its own replaces it for swaps into that pose.durationfloat?Override the transition duration (seconds).
easingEasingMode?Override the transition easing mode.
delayfloat?Override the transition delay (seconds). Ignored when
DurationSecis 0, unless the transition is aSpringwith noRepeatDelaySec, which waits it out.onEnterCompleteActionCallback invoked when the enter transition finishes.
childrenVNode[]Child VNodes rendered inside the motion element.
propsFiberElementPropsOptional FiberElementProps (text / tooltip / enabled / etc.) bag.
eventsFiberEventBinding[]Array of pre-built FiberEventBinding objects applied to the element.
refCallbackFunc<VisualElement, Action>Callback invoked on mount with the created VisualElement; returned Action runs on unmount.
whileHoverClassstringUSS class toggled while the pointer hovers the element.
whileTapClassstringUSS class toggled while the pointer is pressed on the element.
whileFocusClassstringUSS class toggled while the element holds keyboard/UI focus.
elementTypeTypeThe VisualElement type the animated cell IS, e.g.
typeof(Button)so a clickable cell is one element instead of a Motion wrapping a Button. Defaults to UnityEngine.UIElements.VisualElement. Supply interactions viaevents.variantsIReadOnlyDictionary<string, MotionVariant>Named animation states: each label maps to a MotionVariant — a utility class string for that state, plus an optional transition for swaps INTO it (a bare
stringconverts implicitly, takingtransition). The label selected byanimatehas its classes merged on top ofclassName. Because switchinganimatechanges the element's class list, a USStransition-*utility in the classes tweens between states. Parent→child propagation: a descendant Motion that suppliesvariantsbut leavesanimatenull inherits the nearest ANCESTOR Motion's active label and resolves it against its OWN variants — so settinganimateon a parent drives the whole subtree.animatestringThe active variant label (a key of
variants). When this Motion names none ofanimate,initialandexit, the nearest ancestor Motion's labels are inherited; naming any of them, it inherits none.initialstringMount-time starting variant label. The enter starts at
variants[initial]and transitions tovariants[animate](its persistent resting state); with noanimate, the Motion rests atvariants[initial]. The motion guide's Enter on mount section owns who plays the enter and when a presence withholds it. Transition resolves the timing.exitstringExit variant label. When the keyed AnimatePresence child this Motion sits in, however deep, is removed, the Motion animates from its resting pose to
variants[exit]before the child unmounts, and hands the label down to the Motions inheriting its labels. Transition resolves the timing, whether or notvariants[exit]applies a class. Unlikeinitial, this needs AnimatePresence to defer the unmount — set outside one, it is inert, which a warning reports where the mounted tree holds no AnimatePresence at all.layoutIdstringenterOnMountboolFalse mounts this Motion and the Motions below it at their resting pose with no enter (Framer Motion's
initial={false}). Left true, a Motion naming noinitiallabel enters from the look it has without its variant classes.
Returns
- MotionNode
The created MotionNode.