Performance: Dynamic transitions
MEDIUM IMPACT
Dynamic transitions affect the smoothness and speed of visual changes on the page, impacting user interaction responsiveness and visual stability.
<template> <transition :name="transitionName"> <div v-if="show" class="box">Content</div> </transition> </template> <script setup> import { ref } from 'vue' const show = ref(true) const transitionName = ref('fade') </script> <style> .fade-enter-active, .fade-leave-active { transition: opacity 0.5s ease, transform 0.5s ease; will-change: opacity, transform; } .fade-enter-from, .fade-leave-to { opacity: 0; transform: scale(0.8) translateZ(0); } </style>
<template> <transition :name="transitionName"> <div v-if="show" class="box">Content</div> </transition> </template> <script setup> import { ref } from 'vue' const show = ref(true) const transitionName = ref('fade') </script> <style> .fade-enter-active, .fade-leave-active { transition: all 0.5s ease; } .fade-enter-from, .fade-leave-to { opacity: 0; transform: scale(0.8); } </style>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Transition on 'all' properties | No extra DOM nodes | Multiple reflows per frame | High paint cost due to layout changes | [X] Bad |
| Transition on 'opacity' and 'transform' only | No extra DOM nodes | No reflows | Low paint cost, GPU accelerated | [OK] Good |