Performance: Transition directive (transition:fade)
MEDIUM IMPACT
This affects the rendering performance during element appearance and disappearance by animating opacity changes smoothly.
<script> import { fade } from 'svelte/transition'; let visible = false; </script> <button on:click={() => visible = !visible}>Toggle</button> {#if visible} <div transition:fade>Content fades in and out</div> {/if}
<div style="opacity: 0; transition: opacity 0.5s;" bind:this={el}></div> <script> // Manually toggling opacity with JS function show() { el.style.opacity = '1'; } function hide() { el.style.opacity = '0'; } </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual opacity toggle with JS | Multiple style changes | Multiple reflows per toggle | High paint cost due to layout thrashing | [X] Bad |
| Svelte transition:fade directive | Minimal DOM ops | No reflows triggered | Low paint cost, GPU accelerated | [OK] Good |