Chapter 10. Transitioning and Animation in Vue
We have explored all the crucial aspects of building a working Vue application, including handling routes and data flow with proper state management. This chapter will explore a unique Vue feature for enhancing the user experience: animation and transitions, using transition components, hooks, and CSS.
Understanding CSS Transitions and CSS Animations
CSS animations are the visual effects of a state change on a specific element or component, with no limit on the number of states. A CSS animation can start automatically and go into a loop without explicit triggering. In contrast, CSS transition is an animation that responds to a change between two states only, from average to hover for a button or from hidden to visible for a tooltip. To define a CSS animation, we often use the @keyframes rule and then apply it to the target element using the
animation property. For example, we can define a simple animation effect for a
button:
@keyframespulse{0%{box-shadow:0000pxrgba(0,0,0,0.5);}100%{box-shadow:00020pxrgba(0,0,0,0);}}.button{animation:pulse2sinfinite;box-shadow:0px0px1px1px#0000001a;}
We defined a simple animation effect, pulse, and applied it to any element with button class, where the box shadow will expand and shrink in a loop, lasting two seconds. This effect will run infinitely if the element exists in the DOM.
Figure 10-1. Indefinite pulse animation effect
Meanwhile, we can use the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access