Transition API
Detailed listing of all transition related features of Svelte Motion. A lot of the wording is directly copied from framer-motion, Copyright (c) 2018 Framer B.V. MIT License.
Inertia
interface
An animation that decelerates a value based on its initial velocity,
usually used to implement inertial scrolling.
Optionally, `min` and `max` boundaries can be defined, and inertia
will snap to these with a spring animation.
This animation will automatically precalculate a target value,
which can be modified with the `modifyTarget` property.
This allows you to add snap-to-grid or similar functionality.
Inertia is also the animation used for `dragTransition`, and can be configured via that prop.
type: "inertia"
Set `type` to animate using the inertia animation. Set to `"tween"` by
default. This can be used for natural deceleration, like momentum scrolling.modifyTarget: (v: number) => number
A function that receives the automatically-calculated target and returns a new one. Useful for snapping the target to a grid.bounceStiffness: number
If `min` or `max` is set, this affects the stiffness of the bounce
spring. Higher values will create more sudden movement. Set to `500` by
default.bounceDamping: number
If `min` or `max` is set, this affects the damping of the bounce spring.
If set to `0`, spring will oscillate indefinitely. Set to `10` by
default.power: number
A higher power value equals a further target. Set to `0.8` by default.timeConstant: number
Adjusting the time constant will change the duration of the
deceleration, thereby affecting its feel. Set to `700` by default.restDelta: number
End the animation if the distance to the animation target is below this value, and the absolute speed is below `restSpeed`.
When the animation ends, the value gets snapped to the animation target. Set to `0.01` by default.
Generally the default values provide smooth animation endings, only in rare cases should you need to customize these.min: number
Minimum constraint. If set, the value will "bump" against this value (or immediately spring to it if the animation starts as less than this value).max: number
Maximum constraint. If set, the value will "bump" against this value (or immediately snap to it, if the initial animation value exceeds this value).from: number | string
The value to animate from. By default, this is the current state of the animating value.velocity: number
The initial velocity of the animation.
By default this is the current velocity of the component.
Just
interface
For internal use only.
Keyframes
interface
Keyframes tweens between multiple `values`.
These tweens can be arranged using the `duration`, `easings`, and `times` properties.
type: keyframes
Set `type` to `"keyframes"` to animate using the keyframes animation.
Set to `"tween"` by default. This can be used to animate between a series of values.times: number[]
An array of numbers between 0 and 1, where `1` represents the `total` duration.
Each value represents at which point during the animation each item in the animation target should be hit, so the array should be the same length as `values`.
Defaults to an array of evenly-spread durations.ease: Easing | Easing []
An array of easing functions for each generated tween, or a single easing function applied to all tweens.
This array should be one item less than `values`, as these easings apply to the transitions *between* the `values`.duration: number
The total duration of the animation. Set to `0.3` by default.repeatDelay: number
None
interface
Instant transition.
type: false
Set `type` to `false` for an instant transition.
Orchestration
interface
Options for orchestrating the timing of animations.
delay: number
Delay the animation by this duration (in seconds). Defaults to `0`.when: false | "beforeChildren" | "afterChildren" | string
Describes the relationship between the transition and its children. Set
to `false` by default.
When using variants, the transition can be scheduled in relation to its
children with either `"beforeChildren"` to finish this transition before
starting children transitions, `"afterChildren"` to finish children
transitions before starting this transition.delayChildren: number
When using variants, children animations will start after this duration
(in seconds). You can add the `transition` property to the `variant` directly. This generally offers more flexibility, as it allows you to customize the delay per visual state.staggerChildren: number
When using variants, animations of child components can be staggered by this
duration (in seconds).
For instance, if `staggerChildren` is `0.01`, the first child will be
delayed by `0` seconds, the second by `0.01`, the third by `0.02` and so
on.
The calculated stagger delay will be added to `delayChildren`.staggerDirection: number
The direction in which to stagger children.
A value of `1` staggers from the first to the last while `-1`
staggers from the last to the first.
PermissiveTransitionDefinition
{[key: string]: any}
Repeat
repeat: number
The number of times to repeat the transition. Set to `Infinity` for perpetual repeating.
Without setting `repeatType`, this will loop the animation.repeatType: "loop" | "reverse" | "mirror"
How to repeat the animation. This can be either:
"loop": Repeats the animation from the start
"reverse": Alternates between forward and backwards playback
"mirror": Switches `from` and `to` alternatelyrepeatDelay: number
When repeating an animation, `repeatDelay` will set the duration of the time to wait, in seconds, between each repetition.
Spring
interface extends Repeat
An animation that simulates spring physics for realistic motion.
This is the default animation for physical values like `x`, `y`, `scale` and `rotate`.
type: "spring"
Set `type` to `"spring"` to animate using spring physics for natural
* movement. Type is set to `"spring"` by default.stiffness: number
Stiffness of the spring. Higher values will create more sudden movement.
Set to `100` by default.damping: number
Strength of opposing force. If set to 0, spring will oscillate
indefinitely. Set to `10` by default.mass: number
Mass of the moving object. Higher values will result in more lethargic
movement. Set to `1` by default.duration: number
The duration of the animation, defined in seconds. Spring animations can be a maximum of 10 seconds.
If `bounce` is set, this defaults to `0.8`.
Note: `duration` and `bounce` will be overridden if `stiffness`, `damping` or `mass` are set.bounce: number
`bounce` determines the "bounciness" of a spring animation.
`0` is no bounce, and `1` is extremely bouncy.
If `duration` is set, this defaults to `0.25`.
Note: `bounce` and `duration` will be overridden if `stiffness`, `damping` or `mass` are set.restSpeed: number
End animation if absolute speed (in units per second) drops below this
value and delta is smaller than `restDelta`. Set to `0.01` by default.restDelta: number
End animation if distance is below this value and speed is below
`restSpeed`. When animation ends, spring gets “snapped” to. Set to
`0.01` by default.from: number | string
The value to animate from.
By default, this is the initial state of the animating value.velocity: number
The initial velocity of the spring. By default this is the current velocity of the component.
Transition
Orchestration & Repeat & (TransitionDefinition | TransitionMap )
TransitionDefinition
Tween | Spring | Keyframes | Inertia | Just | None | PermissiveTransitionDefinition
List of all possible transition types.
TransitionMap
Orchestration & {[key: string]: TransitionDefinition }
Tween
interface extends Repeat
An animation that animates between two or more values over a specific duration of time.
This is the default animation for non-physical values like `color` and `opacity`.
type: tween
Set `type` to `"tween"` to use a duration-based tween animation.
* If any non-orchestration `transition` values are set without a `type` property,
* this is used as the default animation.duration: number
The duration of the tween animation. Set to `0.3` by default, 0r `0.8` if animating a series of keyframes.ease: Easing | Easing []
The easing function to use. Set as one of the below.
- The name of an existing easing function.
- An array of four numbers to define a cubic bezier curve.
- An easing function, that accepts and returns a value `0-1`.
If the animating value is set as an array of multiple values for a keyframes
animation, `ease` can be set as an array of easing functions to set different easings between
each of those values.times: number[]
When animating keyframes, `times` can be used to determine where in the animation each keyframe is reached.
Each value in `times` is a value between `0` and `1`, representing `duration`.
There must be the same number of `times` as there are keyframes.
Defaults to an array of evenly-spread durations.easings: Easing []
When animating keyframes, `easings` can be used to define easing functions between each keyframe. This array should be one item fewer than the number of keyframes, as these easings apply to the transitions between the keyframes.from: number | string
The value to animate from.
By default, this is the current state of the animating value.