Complete the code to apply a fade transition to the paragraph when it appears.
<script> import { fade } from 'svelte/transition'; let visible = true; </script> <button on:click={() => visible = !visible}>Toggle</button> {#if visible} <p [1]={fade}>Hello, I fade in and out!</p> {/if}
The correct syntax to apply a fade transition in Svelte is transition:fade. This tells Svelte to use the fade transition when the element enters or leaves the DOM.
Complete the code to import the fade transition correctly.
<script> import [1] from 'svelte/transition'; let show = true; </script>
The fade transition is exported as fade from 'svelte/transition'. You must import it exactly as fade to use it.
Fix the error in the transition directive to make the fade work.
<p transition=[1]>Fade me!</p>The transition directive expects the name of the transition function without parentheses or braces. So use transition:fade, not transition:fade() or transition:{fade}.
Fill both blanks to create a fade transition with a duration of 500 milliseconds.
<script> import { fade } from 'svelte/transition'; let visible = true; </script> {#if visible} <div [1]={{fade}} [2]={{ duration: 500 }}>Fade with duration</div> {/if}
The correct syntax is transition:fade={{ duration: 500 }}. The first blank is the directive name transition:fade, and the second blank is the attribute to pass parameters, which is just transition in this context.
Fill all three blanks to create a fade transition that starts with opacity 0 and lasts 1000 milliseconds.
<script> import { fade } from 'svelte/transition'; let show = true; </script> {#if show} <section [1]={{fade}} [2]={{ duration: [3] }}>Welcome!</section> {/if}
Use transition:fade to apply the fade. The duration option is passed as duration: 1000 to make it last 1 second.