【问题标题】:Angular2 animation learning resources [closed]Angular2动画学习资源[关闭]
【发布时间】:2016-06-15 18:13:30
【问题描述】:

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

【问题讨论】:

标签: angular ng-animate


【解决方案1】:

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

【讨论】:

  • 感谢 plunkr 示例。对于使用流行的 animate.css daneden.github.io/animate.css 之类的动画库来处理动画与必须编写和测试原始 CSS(如 sn-p 中所示)相比,您有何看法?
  • 如果它有你想要使用的动画,我肯定会使用它。动画一直是 javascript 库的需求功能,但您可以看到 css 动画非常简单(1 行!)而且如果您知道自己在做什么(我不知道)。为什么要增加应用程序代码的复杂性?包括动画在内的样式都属于样式表。
猜你喜欢
  • 2011-07-02
  • 1970-01-01
  • 2011-05-19
  • 2011-09-19
  • 2010-11-27
  • 1970-01-01
  • 1970-01-01
  • 2010-12-04
  • 2011-08-19
相关资源
最近更新 更多