Runtime
Transitions
The svelte/transition
module exports seven functions: fade
, blur
, fly
, slide
, scale
,
draw
and crossfade
. They are for use with Svelte transitions
.
fade
Animates the opacity of an element from 0 to the current opacity for in
transitions and from the current opacity to 0 for out
transitions.
fade
accepts the following parameters:
delay
(number
, default 0) — milliseconds before startingduration
(number
, default 400) — milliseconds the transition lastseasing
(function
, defaultlinear
) — an easing function
You can see the fade
transition in action in the transition tutorial.
blur
Animates a blur
filter alongside an element's opacity.
blur
accepts the following parameters:
delay
(number
, default 0) — milliseconds before startingduration
(number
, default 400) — milliseconds the transition lastseasing
(function
, defaultcubicInOut
) — an easing functionopacity
(number
, default 0) - the opacity value to animate out to and in fromamount
(number
, default 5) - the size of the blur in pixels
fly
Animates the x and y positions and the opacity of an element. in
transitions animate from an element's current (default) values to the provided values, passed as parameters. out
transitions animate from the provided values to an element's default values.
fly
accepts the following parameters:
delay
(number
, default 0) — milliseconds before startingduration
(number
, default 400) — milliseconds the transition lastseasing
(function
, defaultcubicOut
) — an easing functionx
(number
, default 0) - the x offset to animate out to and in fromy
(number
, default 0) - the y offset to animate out to and in fromopacity
(number
, default 0) - the opacity value to animate out to and in from
You can see the fly
transition in action in the transition tutorial.
slide
Slides an element in and out.
slide
accepts the following parameters:
delay
(number
, default 0) — milliseconds before startingduration
(number
, default 400) — milliseconds the transition lastseasing
(function
, defaultcubicOut
) — an easing function
scale
Animates the opacity and scale of an element. in
transitions animate from an element's current (default) values to the provided values, passed as parameters. out
transitions animate from the provided values to an element's default values.
scale
accepts the following parameters:
delay
(number
, default 0) — milliseconds before startingduration
(number
, default 400) — milliseconds the transition lastseasing
(function
, defaultcubicOut
) — an easing functionstart
(number
, default 0) - the scale value to animate out to and in fromopacity
(number
, default 0) - the opacity value to animate out to and in from
draw
Animates the stroke of an SVG element, like a snake in a tube. in
transitions begin with the path invisible and draw the path to the screen over time. out
transitions start in a visible state and gradually erase the path. draw
only works with elements that have a getTotalLength
method, like <path>
and <polyline>
.
draw
accepts the following parameters:
delay
(number
, default 0) — milliseconds before startingspeed
(number
, default undefined) - the speed of the animation, see below.duration
(number
|function
, default 800) — milliseconds the transition lastseasing
(function
, defaultcubicInOut
) — an easing function
The speed
parameter is a means of setting the duration of the transition relative to the path's length. It is a modifier that is applied to the length of the path: duration = length / speed
. A path that is 1000 pixels with a speed of 1 will have a duration of 1000ms
, setting the speed to 0.5
will double that duration and setting it to 2
will halve it.
crossfade
The crossfade
function creates a pair of transitions called send
and receive
. When an element is 'sent', it looks for a corresponding element being 'received', and generates a transition that transforms the element to its counterpart's position and fades it out. When an element is 'received', the reverse happens. If there is no counterpart, the fallback
transition is used.
crossfade
accepts the following parameters:
delay
(number
, default 0) — milliseconds before startingduration
(number
|function
, default 800) — milliseconds the transition lastseasing
(function
, defaultcubicOut
) — an easing functionfallback
(function
) — A fallback transition to use for send when there is no matching element being received, and for receive when there is no element being sent.