Example code of the angular2 series route transition animation and angular2 example code

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.