Performance: CSS transition classes
MEDIUM IMPACT
CSS transition classes affect the smoothness and speed of visual changes, impacting user interaction responsiveness and visual stability.
<template> <transition name="fade"> <div v-if="show">Content</div> </transition> </template> <style> .fade-enter-active, .fade-leave-active { transition: opacity 0.5s ease; } .fade-enter, .fade-leave-to { opacity: 0; } </style>
<template> <div :class="{ 'fade-enter-active': show, 'fade-leave-active': !show }">Content</div> </template> <style> .fade-enter-active, .fade-leave-active { transition: all 0.5s ease; } .fade-enter, .fade-leave-to { opacity: 0; height: 0; } </style>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Transition all properties including height | No extra DOM nodes | Multiple reflows per frame | High paint cost due to layout changes | [X] Bad |
| Transition opacity only with Vue <transition> | No extra DOM nodes | No reflows | Low paint cost, uses compositor | [OK] Good |