Performance: Custom transitions
Custom transitions affect the rendering speed and smoothness of animations during element entry and exit, impacting user interaction responsiveness and visual stability.
import { cubicOut } from 'svelte/easing'; function simpleTransition(node, { duration }) { return { duration, css: t => `transform: translateX(${t * 100}px); opacity: ${t}` }; } // Usage: <div transition:simpleTransition={{ duration: 300 }}>Content</div>
import { cubicOut } from 'svelte/easing'; function heavyTransition(node, { duration }) { const start = performance.now(); return { duration, css: t => { // Complex calculation on every frame const progress = Math.sin(t * Math.PI * 10) * 100; return `transform: translateX(${progress}px); opacity: ${t}`; } }; } // Usage: <div transition:heavyTransition={{ duration: 1000 }}>Content</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy math in css function | Minimal (1 element) | Multiple per frame | High (layout-triggering) | [X] Bad |
| Simple transform and opacity | Minimal (1 element) | None | Low (GPU accelerated) | [OK] Good |
custom transition in Svelte?node and optionally params.duration and a css function using t for progress.function slide(node) {
return {
duration: 400,
css: t => `transform: translateX(${(1 - t) * 100}%)`
};
}transition:slide?function grow(node) {
return {
duration: 500,
css: t => `scale(${t})`
};
}Pass the test and this pattern moves unknown