Consider a Svelte component that uses crossfade to animate list items when they are removed. What is the visible behavior when an item is deleted?
import { crossfade } from 'svelte/transition'; const [send, receive] = crossfade({ duration: 400 }); let items = ['apple', 'banana', 'cherry']; function removeItem(item) { items = items.filter(i => i !== item); }
Think about how crossfade combines fading and movement to create smooth transitions.
Svelte's crossfade transition animates the removed item by fading it out while moving it to the position of the incoming item, creating a smooth visual effect.
Choose the correct way to apply crossfade transitions to a list of items in Svelte.
import { crossfade } from 'svelte/transition'; const [send, receive] = crossfade({ duration: 300 }); let items = ['one', 'two', 'three'];
Remember that crossfade returns two functions: one for items leaving and one for items entering.
You must use in:receive for items entering and out:send for items leaving to properly apply crossfade transitions.
Given this Svelte code, the crossfade animation does not run when items are added or removed. What is the most likely cause?
import { crossfade } from 'svelte/transition'; const [send, receive] = crossfade({ duration: 500 }); let items = ['a', 'b', 'c']; // In markup: // {#each items as item}<div in:receive out:send>{item}</div>{/each}
Think about how Svelte tracks list items for transitions.
Svelte requires a unique key in the each block to track items and apply transitions correctly. Without keys, animations won't trigger.
In Svelte's crossfade transition, what do the send and receive functions represent?
Consider the direction of the animation for items leaving and entering.
send handles the animation of elements leaving the DOM, while receive handles elements entering, enabling smooth crossfade effects.
Given a Svelte list ['x', 'y', 'z'] with crossfade applied, if you swap the positions of 'x' and 'z' in the array, what will happen?
import { crossfade } from 'svelte/transition'; const [send, receive] = crossfade({ duration: 400 }); let items = ['x', 'y', 'z']; function swap() { items = ['z', 'y', 'x']; } // In markup: // {#each items as item (item)}<div in:receive out:send>{item}</div>{/each}
Think about how crossfade matches elements by their keys during reordering.
Crossfade matches items by their keys and animates their movement smoothly to new positions without fading out completely.