2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								include ../_util-fns
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Motion is an important aspect in the design of modern web applications. Good
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  user interfaces transition smoothly between states with engaging animations
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  that call attention where it's needed. Well-designed animations can make a UI not only
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  more fun but also easier to use.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Angular's animation system lets you build animations that run with the same kind of native
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  performance found in pure CSS animations. You can also tightly integrate your
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  animation logic with the rest of your application code, for ease of control.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.alert.is-helpful
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Angular animations are built on top of the standard [Web Animations API](https://w3c.github.io/web-animations/)
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    and run natively on [browsers that support it](http://caniuse.com/#feat=web-animation).
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    For other browsers, a polyfill is required. Grab
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    [`web-animations.min.js` from GitHub](https://github.com/web-animations/web-animations-js) and
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    add it to your page.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  # Contents
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Example: Transitioning between two states](#example-transitioning-between-states).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [States and transitions](#states-and-transitions).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Example: Entering and leaving](#example-entering-and-leaving).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Example: Entering and leaving from different states](#example-entering-and-leaving-from-different-states).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Animatable properties and units](#animatable-properties-and-units).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Automatic property calculation](#automatic-property-calculation).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Animation timing](#animation-timing).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Multi-step animations with keyframes](#multi-step-animations-with-keyframes).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Parallel animation groups](#parallel-animation-groups).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * [Animation callbacks](#animation-callbacks).
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      The examples in this page are available as a <live-example></live-example>.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								a(id="example-transitioning-between-states")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Quickstart example: Transitioning between two states
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								figure
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/animation_basic_click.gif" alt="A simple transition animation" align="right" style="width:220px;margin-left:20px" )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  You can build a simple animation that transitions an element between two states
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  driven by a model attribute.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Animations are defined inside `@Component` metadata. Before you can add animations, you need
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  to import a few animation-specific functions:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-basic.component.ts', 'imports')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  With these, you can define an *animation trigger* called `heroState` in the component
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  metadata. It uses animations to transition between two states: `active` and `inactive`. When a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  hero is active, the element appears in a slightly larger size and lighter color.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-basic.component.ts', 'animationdef')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.alert.is-helpful
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    In this example, you are defining animation styles (color and transform) inline in the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    animation metadata.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Now, using the `[@triggerName]` syntax, attach the animation that you just defined to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  one or more elements in the component's template.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-basic.component.ts', 'template')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Here, the animation trigger applies to every element repeated by an `ngFor`. Each of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  the repeated elements animates independently. The value of the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  attribute is bound to the expression `hero.state` and is always either `active` or `inactive`.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  With this setup, an animated transition appears whenever a hero object changes state.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  Here's the full component implementation:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-basic.component.ts')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## States and transitions
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Angular animations are defined as logical **states** and **transitions**
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  between states.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  An animation state is a string value that you define in your application code. In the example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  above, the states `'active'` and `'inactive'` are based on the logical state of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  hero objects. The source of the state can be a simple object attribute, as it was in this case,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  or it can be a value computed in a method. The important thing is that you can read it into the
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  component's template.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  You can define *styles* for each animation state:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-basic.component.ts', 'states')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  These `state` definitions specify the *end styles* of each state.
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  They are applied to the element once it has transitioned to that state, and stay
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  *as long as it remains in that state*. In effect, you're defining what styles the element has in different states.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  After you define states, you can define *transitions* between the states. Each transition
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  controls the timing of switching between one set of styles and the next:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-basic.component.ts', 'transitions')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/ng_animate_transitions_inactive_active.png" alt="In Angular animations you define states and transitions between states" width="400")
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  If several transitions have the same timing configuration, you can combine
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  them into the same `transition` definition:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-combined-transitions.component.ts', 'transitions')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  When both directions of a transition have the same timing, as in the previous
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  example, you can use the shorthand syntax `<=>`:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-twoway.component.ts', 'transitions')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  You can also apply a style during an animation but not keep it around
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  after the animation finishes. You can define such styles inline, in the `transition`. In this example,
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  the element receives one set of styles immediately and is then animated to the next.
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  When the transition finishes, none of these styles are kept because they're not
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  defined in a `state`.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-inline-styles.component.ts', 'transitions')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ### The wildcard state `*`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The `*` ("wildcard") state matches *any* animation state. This is useful for defining styles and
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  transitions that apply regardless of which state the animation is in. For example:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * The `active => *` transition applies when the element's state changes from `active` to anything else.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * The `* => *` transition applies when *any* change between two states takes place.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/ng_animate_transitions_inactive_active_wildcards.png" alt="The wildcard state can be used to match many different transitions at once" width="400")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ### The `void` state
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  The special state called `void` can apply to any animation. It applies
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  when the element is *not* attached to a view, perhaps because it has not yet been
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  added or because it has been removed. The `void` state is useful for defining enter and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  leave animations.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  For example the `* => void` transition applies when the element leaves the view,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  regardless of what state it was in before it left.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/ng_animate_transitions_void_in.png" alt="The void state can be used for enter and leave transitions" width="400")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The wildcard state `*` also matches `void`.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Example: Entering and leaving
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								figure
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/animation_enter_leave.gif" alt="Enter and leave animations" align="right" style="width:250px;" )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Using the `void` and `*` states you can define transitions that animate the
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  entering and leaving of elements:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Enter: `void => *`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Leave: `* => void`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-enter-leave.component.ts', 'animationdef')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Note that in this case the styles are applied to the void state directly in the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  transition definitions, and not in a separate `state(void)` definition. Thus, the transforms
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  are different on enter and leave: the element enters from the left
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  and leaves to the right.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Example: Entering and leaving from different states
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								figure
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/animation_enter_leave_states.gif" alt="Enter and leave animations combined with state animations" align="right" style="width:200px" )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  You can also combine this animation with the earlier state transition animation by
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  using the hero state as the animation state. This lets you configure
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  different transitions for entering and leaving based on what the state of the hero
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  is:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Inactive hero enter: `void => inactive`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Active hero enter: `void => active`
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 18:54:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  * Inactive hero leave: `inactive => void`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Active hero leave: `active => void`
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  This gives you fine-grained control over each transition:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/ng_animate_transitions_inactive_active_void.png" alt="This example transitions between active, inactive, and void states" width="400")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-enter-leave-states.component.ts', 'animationdef')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Animatable properties and units
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Since Angular's animation support builds on top of Web Animations, you can animate any property
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  that the browser considers *animatable*. This includes positions, sizes, transforms, colors,
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  borders, and many others. The W3C maintains
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  [a list of animatable properties](https://www.w3.org/TR/css3-transitions/#animatable-properties)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  on its [CSS Transitions page](https://www.w3.org/TR/css3-transitions).
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  For positional properties that have a numeric value, you can define a unit by providing
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  the value as a string with the appropriate suffix:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * `'50px'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * `'3em'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * `'100%'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  If you don't provide a unit when specifying dimension, Angular assumes the default of `px`:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * `50` is the same as saying `'50px'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Automatic property calculation
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								figure
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/animation_auto.gif" alt="Animation with automated height calculation" align="right" style="width:220px;margin-left:20px" )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Sometimes you don't know the value of a dimensional style property until runtime.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  For example, elements often have widths and heights that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  depend on their content and the screen size. These properties are often tricky
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  to animate with CSS.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  In these cases, you can use a special `*` property value so that the value of the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  property is computed at runtime and then plugged into the animation.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  In this example, the leave animation takes whatever height the element has before it
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  leaves and animates from that height to zero:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-auto.component.ts', 'animationdef')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Animation timing
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  There are three timing properties you can tune for every animated transition:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  the duration, the delay, and the easing function. They are all combined into
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  a single transition *timing string*.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ### Duration
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The duration controls how long the animation takes to run from start to finish.
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  You can define a duration in three ways:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * As a plain number, in milliseconds: `100`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * In a string, as milliseconds: `'100ms'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * In a string, as seconds: `'0.1s'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ### Delay
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  The delay controls the length of time between the animation trigger and the beginning
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  of the transition. You can define one by adding it to the same string
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  following the duration. It also has the same format options as the duration:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Wait for 100ms and then run for 200ms: `'0.2s 100ms'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ### Easing
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The [easing function](http://easings.net/) controls how the animation accelerates
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  and decelerates during its runtime. For example, an `ease-in` function causes
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  the animation to begin relatively slowly but pick up speed as it progresses. You
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  can control the easing by adding it as a *third* value in the string after the duration
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  and the delay (or as the *second* value when there is no delay):
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Wait for 100ms and then run for 200ms, with easing: `'0.2s 100ms ease-out'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  * Run for 200ms, with easing: `'0.2s ease-in-out'`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								figure
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/animation_timings.gif" alt="Animations with specific timings" align="right" style="width:220px;margin-left:20px" )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ### Example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Here are a couple of custom timings in action. Both enter and leave last for
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  200 milliseconds but they have different easings. The leave begins after a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  slight delay:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-timings.component.ts', 'animationdef')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Multi-step animations with keyframes
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								figure
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/animation_multistep.gif" alt="Animations with some bounce implemented with keyframes" align="right" style="width:220px;margin-left:20px" )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Animation *keyframes* go beyond a simple transition to a more intricate animation
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  that goes through one or more intermediate styles when transitioning between two sets of styles.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  For each keyframe, you specify an *offset* that defines at which point
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  in the animation that keyframe applies. The offset is a number between zero,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  which marks the beginning of the animation, and one, which marks the end.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  This example adds some "bounce" to the enter and leave animations with
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  keyframes:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-multistep.component.ts', 'animationdef')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Note that the offsets are *not* defined in terms of absolute time. They are relative
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  measures from zero to one. The final timeline of the animation is based on the combination
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  of keyframe offsets, duration, delay, and easing.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Defining offsets for keyframes is optional. If you omit them, offsets with even
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  spacing are automatically assigned. For example, three keyframes without predefined
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  offsets receive offsets `0`, `0.5`, and `1`.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Parallel animation groups
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								figure
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  img(src="/resources/images/devguide/animations/animation_groups.gif" alt="Parallel animations with different timings, implemented with groups" align="right" style="width:220px;margin-left:20px" )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  You've seen how to animate multiple style properties at the same time:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  just put all of them into the same `style()` definition.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  But you may also want to configure different *timings* for animations that happen
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  in parallel. For example, you may want to animate two CSS properties but use a
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  different easing function for each one.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  For this you can use animation *groups*. In this example, using groups both on
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  enter and leave allows for two different timing configurations. Both
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  are applied to the same element in parallel, but run independently of each other:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-08 15:41:37 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-groups.component.ts', 'animationdef')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  One group animates the element transform and width; the other group animates the opacity.
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 00:57:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ## Animation callbacks
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  A callback is fired when an animation is started and also when it is done.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-20 17:31:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  In the keyframes example, you have a `trigger` called `@flyInOut`. There you can hook
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  those callbacks like this:
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 00:57:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+makeExample('animations/ts/app/hero-list-multistep.component.ts', 'template')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The callbacks receive an `AnimationTransitionEvent` which contains useful properties such as `fromState`,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  `toState` and `totalTime`.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Those callbacks will fire whether or not an animation is picked up.