Performance: Why transitions enhance UX
MEDIUM IMPACT
Transitions affect the smoothness of visual changes and user interaction responsiveness on a page.
<template><button @click="show = !show">Toggle</button><transition name="fade"><div v-if="show" class="fade">Content</div></transition></template><script setup>import { ref } from 'vue'; const show = ref(false);</script><style>.fade-enter-active, .fade-leave-active { transition: opacity 0.3s ease; } .fade-enter-from, .fade-leave-to { opacity: 0; }</style>
<template><button @click="show = !show">Toggle</button><div v-if="show" style="transition: all 1s;">Content</div></template><script setup>import { ref } from 'vue'; const show = ref(false);</script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Transition on 'all' properties | Normal DOM ops | Multiple reflows triggered | High paint cost | [X] Bad |
| Transition on 'opacity' only | Normal DOM ops | No reflows | Low paint cost (composite only) | [OK] Good |