Performance: In and out transitions
MEDIUM IMPACT
This affects the visual stability and interaction responsiveness during element appearance and disappearance on the page.
<script> import { fly } from 'svelte/transition'; let visible = false; </script> <button on:click={() => visible = !visible}>Toggle</button> {#if visible} <div transition:fly={{ x: 100, duration: 300 }}>{content}</div> {/if}
<script> import { fade } from 'svelte/transition'; let visible = false; </script> <button on:click={() => visible = !visible}>Toggle</button> {#if visible} <div transition:fade>{content}</div> {/if}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fade with opacity only | Minimal DOM changes | 0 reflows if no size change | Low paint cost | [OK] Good |
| Fade combined with size changes | DOM changes on size | Multiple reflows | High paint cost | [X] Bad |
| Fly transition (transform + opacity) | Minimal DOM changes | 0 reflows | Low paint cost, GPU accelerated | [OK] Good |