2016-06-15 148 views
0

是否有任何可用于学习的良好/深度资源Angular2中的动画除了www.angular.io上的基本API参考吗?Angular2动画学习资源

+0

https://www.youtube.com/results?search_query=ng-conf+动画,但尚未可用 - 可能RC2 –

回答

2

Angular 2中的动画在开发过程中发生了很多次变化,并在RC2中再次发生变化。 Here is a resource that I used for an app using RC1,虽然这项技术还没有正式提供,并且没有记录。正如文章顶部所述,RC2中有一个新库。

我承认我没有试过RC2,但这里是我的要求。您不需要动画库(对于大多数情况)。只需使用css转换classstyle指令。

作为一个例子,到链接物品类似的功能可以与该代码来实现:

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

+0

感谢您的plunkr例子。如何使用动画库(如流行的animate.css [daneden.github.io/animate.css](https://daneden.github.io/animate.css))来处理动画,而不必写和测试原始CSS,如你的代码片段所示? –

+0

我肯定会使用它,如果它有你想要使用的动画。动画一直是javascript库的按需特征,但是你可以看到css动画是非常简单的(1行!),如果你知道你在做什么(我没有),它也非常强大。为什么增加应用程序代码的复杂性?样式,包括动画属于样式表。 – threeve