Example code of the angular2 series route transition animation and angular2 example code
Angular2's animation system gives you the ability to make a variety of animation effects, and strives to build an animation with the same performance as the native CSS animation.
Angular2 animation is mainly combined with @ Component.
The animations metadata attribute is decorated in the definition @ Component. Just like the metadata attribute of template! In this way, the animation logic can be tightly integrated with its application code, which makes it easier for the animation to start and control.
1. Introduce in app. mudule. ts:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
Add the following in imports in @ NgModule:
imports: [BrowserAnimationsModule],
2. Create a file named animations. ts to write a transfer animation.
Import {animate, AnimationEntryMetadata, state, style, transition, trigger} from '@ angular/core'; // Component transition animationsexport const slideInDownAnimation: animationEntryMetadata = // animation trigger name trigger ('routeanimation ', [state (' * ', style ({opacity: 1, transform: 'translatex (0 )'})), transition (': enter', [style ({opacity: 0, transform: 'translatex (-100%)'}), animate ('0. 2 s queue-in ')]), transition (': leave ', [animate ('0. 5 s extract-out ', style ({opacity: 0, transform: 'translatey (100%)'})]);
3. perform operations on the page where you want to add a transfer Animation
Import {HostBinding} from '@ angular/core ...)
Introduce the animation template you have written: import {slideInDownAnimation} from '../animation ';
Add: animations: [slideInDownAnimation] to @ Component,
Finally:
// Add the @ HostBinding attribute to the class to set the animation and style of the route component element @ HostBinding ('@ routeAnimation') routeAnimation = true; @ HostBinding ('style. display') display = 'block'; @ HostBinding ('style. position ') position = 'absolute ';
4. Now you can go to the browser to check the effect. If there is no error
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.