Complete the code to import the built-in fade transition from Svelte.
import { [1] } from 'svelte/transition';
The fade transition is imported from svelte/transition to create a fade effect.
Complete the code to apply a fade transition to the div when it appears or disappears.
<div transition:[1]>{{message}}</div>The transition:fade directive applies the fade effect to the element.
Fix the error in the custom transition function to return the correct object shape.
function customFade(node, { duration = 400 } = {}) {
return {
[1]: duration,
css: t => `opacity: ${t}`
};
}The returned object must have a duration property to specify how long the transition lasts.
Fill both blanks to create a custom transition that changes opacity and scales the element.
function scaleFade(node, { duration = 300 } = {}) {
return {
[1]: duration,
css: t => `opacity: ${t}; transform: scale(${ [2] });`
};
}The duration property sets how long the transition lasts, and t controls the scale from 0 to 1 as the transition progresses.
Fill all three blanks to use the custom transition with parameters in the component.
<script> import { cubicOut } from 'svelte/easing'; function customTransition(node, { delay = 0, duration = 400, easing = cubicOut } = {}) { return { [1]: delay, duration: duration, easing: easing, css: t => `opacity: ${t}; transform: translateX(${(1 - t) * 100}px);` }; } </script> <div transition:customTransition={{ delay: [2], duration: [3] }}> Slide and fade in </div>
The first blank is the property name delay in the returned object. The second and third blanks are the values for delay and duration passed to the transition in the component.