Angular2 animation learning resources [closed]

喜夏-厌秋 提交于 2019-12-12 03:24:38

问题


Are there any good / in depth resources available for learning animation in Angular2 apart from the basic API reference on www.angular.io ?


回答1:


Animation in Angular 2 has changed many times during development, and is changing again in RC2. Here is a resource that I used for an app using RC1, though the technique was not officially available, and undocumented. As it says at the top of the article, there is a new library in RC2.

I confess that I have not tried RC2, but here is my take. You don't need an animation library (for most things). Just use css transitions with class and style directives.

As an example, similar functionality to the linked article can be achieved with this code:

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  template: `
             <button (click)='toggleHeight()'>Show/Hide</button>
             <div [style.height]='divHeight'>
                Sed ut perspiciatis unde omnis iste natus error sit
                voluptatem accusantium doloremque laudantium, totam
                aperiam, eaque ipsa quae ab illo inventore...
             </div>
            `,
   styles:  [`
              div {
                overflow-y: hidden;
                transition: height 2s ease;
              }
            `]
})
export class AppComponent {
    divHeight: string = '500px';
    shown: boolean = true;

    toggleHeight() {
        this.shown = !this.shown
      this.divHeight = this.shown? '500px' : '0';
    }
}

Here is working plunkr



来源:https://stackoverflow.com/questions/37842840/angular2-animation-learning-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!