Consider this Svelte component snippet using a fade transition with a duration of 1000ms and a delay of 500ms:
<script>
import { fade } from 'svelte/transition';
let visible = false;
</script>
<button on:click={() => visible = !visible}>Toggle</button>
{#if visible}
<div transition:fade={{ duration: 1000, delay: 500 }}>Hello</div>
{/if}What will the user see when toggling the visibility on?
<script> import { fade } from 'svelte/transition'; let visible = false; </script> <button on:click={() => visible = !visible}>Toggle</button> {#if visible} <div transition:fade={{ duration: 1000, delay: 500 }}>Hello</div> {/if}
Think about what the delay parameter does before the transition starts.
The delay parameter postpones the start of the fade effect by 500ms. After this delay, the fade transition runs for 1000ms, making the text appear gradually.
Choose the correct syntax to apply a slide transition with a duration of 2000 milliseconds and a delay of 300 milliseconds.
Remember that Svelte transition parameters use double curly braces with key-value pairs.
The correct syntax uses double curly braces with an object: transition:slide={{ duration: 2000, delay: 300 }}. Other options use invalid syntax.
Given this Svelte code snippet:
{#if show}
<div transition:fly={{ duration: 1500, delay: 700 }}>Welcome</div>
{/if}If show becomes true at time 0, after how many milliseconds will the element be fully visible?
{#if show}
<div transition:fly={{ duration: 1500, delay: 700 }}>Welcome</div>
{/if}Add the delay and duration times to find the total transition time.
The element waits 700ms (delay) before starting the 1500ms (duration) transition. Total time = 700 + 1500 = 2200ms.
Look at this Svelte code:
{#if visible}
<div transition:fade={{ duration: 1000, delay: '500' }}>Hi</div>
{/if}The developer expects a 500ms delay before fade starts, but the delay seems ignored. Why?
{#if visible}
<div transition:fade={{ duration: 1000, delay: '500' }}>Hi</div>
{/if}Check the data type of the delay parameter.
Svelte expects delay as a number, not a string. Using a string causes the delay to be ignored.
In Svelte transitions, what is the correct relationship between duration and delay parameters regarding the element's lifecycle during enter and leave?
Think about what happens first: waiting or transitioning.
Delay waits before the transition starts. Duration is how long the transition effect lasts. Together, they determine when the element fully appears or disappears.