animate() — svelte Function Reference
Architecture documentation for the animate() function in transitions.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD df0bba2e_5fd6_624d_e576_6c964cadc587["animate()"] e29c417d_6c26_6125_97f5_600e95e02dac["transitions.js"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|defined in| e29c417d_6c26_6125_97f5_600e95e02dac ad39f2bb_e258_bd5a_b2ab_4d60ed2d92f6["animation()"] ad39f2bb_e258_bd5a_b2ab_4d60ed2d92f6 -->|calls| df0bba2e_5fd6_624d_e576_6c964cadc587 44764042_8b9f_4b88_947a_7c8b4732666d["transition()"] 44764042_8b9f_4b88_947a_7c8b4732666d -->|calls| df0bba2e_5fd6_624d_e576_6c964cadc587 cf9fafcc_74cf_96c6_92b8_d5c64c62efa0["is_function()"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|calls| cf9fafcc_74cf_96c6_92b8_d5c64c62efa0 44764042_8b9f_4b88_947a_7c8b4732666d["transition()"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|calls| 44764042_8b9f_4b88_947a_7c8b4732666d 2cab0f64_6d19_d981_66e2_d2555c252702["queue_micro_task()"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|calls| 2cab0f64_6d19_d981_66e2_d2555c252702 df3eb428_b4f0_dfc3_ea43_9d12d88502ee["dispatch_event()"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|calls| df3eb428_b4f0_dfc3_ea43_9d12d88502ee a53cae39_471c_2887_0e0b_eedb385d245a["tick()"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|calls| a53cae39_471c_2887_0e0b_eedb385d245a 50007ed7_a19a_bc0a_f3b9_9559a7d8d4a9["css_to_keyframe()"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|calls| 50007ed7_a19a_bc0a_f3b9_9559a7d8d4a9 185b398a_1ddd_d231_9999_8110452fa052["loop()"] df0bba2e_5fd6_624d_e576_6c964cadc587 -->|calls| 185b398a_1ddd_d231_9999_8110452fa052 style df0bba2e_5fd6_624d_e576_6c964cadc587 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/internal/client/dom/elements/transitions.js lines 312–471
function animate(element, options, counterpart, t2, on_finish) {
var is_intro = t2 === 1;
if (is_function(options)) {
// In the case of a deferred transition (such as `crossfade`), `option` will be
// a function rather than an `AnimationConfig`. We need to call this function
// once the DOM has been updated...
/** @type {Animation} */
var a;
var aborted = false;
queue_micro_task(() => {
if (aborted) return;
var o = options({ direction: is_intro ? 'in' : 'out' });
a = animate(element, o, counterpart, t2, on_finish);
});
// ...but we want to do so without using `async`/`await` everywhere, so
// we return a facade that allows everything to remain synchronous
return {
abort: () => {
aborted = true;
a?.abort();
},
deactivate: () => a.deactivate(),
reset: () => a.reset(),
t: () => a.t()
};
}
counterpart?.deactivate();
if (!options?.duration && !options?.delay) {
dispatch_event(element, is_intro ? 'introstart' : 'outrostart');
on_finish();
return {
abort: noop,
deactivate: noop,
reset: noop,
t: () => t2
};
}
const { delay = 0, css, tick, easing = linear } = options;
var keyframes = [];
if (is_intro && counterpart === undefined) {
if (tick) {
tick(0, 1); // TODO put in nested effect, to avoid interleaved reads/writes?
}
if (css) {
var styles = css_to_keyframe(css(0, 1));
keyframes.push(styles, styles);
}
}
var get_t = () => 1 - t2;
// create a dummy animation that lasts as long as the delay (but with whatever devtools
// multiplier is in effect). in the common case that it is `0`, we keep it anyway so that
// the CSS keyframes aren't created until the DOM is updated
//
// fill forwards to prevent the element from rendering without styles applied
// see https://github.com/sveltejs/svelte/issues/14732
var animation = element.animate(keyframes, { duration: delay, fill: 'forwards' });
animation.onfinish = () => {
// remove dummy animation from the stack to prevent conflict with main animation
animation.cancel();
dispatch_event(element, is_intro ? 'introstart' : 'outrostart');
// for bidirectional transitions, we start from the current position,
// rather than doing a full intro/outro
var t1 = counterpart?.t() ?? 1 - t2;
counterpart?.abort();
var delta = t2 - t1;
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does animate() do?
animate() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/elements/transitions.js.
Where is animate() defined?
animate() is defined in packages/svelte/src/internal/client/dom/elements/transitions.js at line 312.
What does animate() call?
animate() calls 7 function(s): css_to_keyframe, dispatch_event, is_function, loop, queue_micro_task, tick, transition.
What calls animate()?
animate() is called by 2 function(s): animation, transition.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free