首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular 2.1.0 transition()不工作

Angular 2.1.0 transition()不工作
EN

Stack Overflow用户
提问于 2016-10-19 02:07:39
回答 1查看 315关注 0票数 0

我试着在我的angular 2应用程序中添加动画,但它不起作用,我试着使用我从互联网上得到的一个例子,我做了一点研究,但我没有找到任何东西,请任何人帮助我。

代码语言:javascript
复制
import {Component, trigger, state, animate, transition, style} from '@angular/core';

@Component({
  selector: 'app-root',
  styles: [`
    .container {
      background-color: white;
      border: 10px solid black;
      width: 200px;
      text-align: center;
      font-size: 50px;
      box-sizing: border-box;
      overflow: hidden;
    }
  `],
  animations: [
    trigger('openClose', [
      state('collapsed', style({ height: '0px', color: 'red' })),
      state('expanded', style({ height: '100px', color: 'lightgreen' })),
      transition('expanded <=> collapsed', animate(500))
    ])
  ],
  template: `
    <button (click)="expand()">Expand</button>
    <button (click)="collapse()">Collapse</button>
    <hr />
    <div class="container" [@openClose]="animationState">
      Look at this box
    </div>
  `
})
export class AppComponent {
  animationState: string;

  constructor() {
    this.collapse();
  }

  expand() {
    this.animationState = 'expanded';
  }

  collapse() {
    this.animationState = 'collapsed';
  }
}
EN

回答 1

Stack Overflow用户

发布于 2017-06-19 17:06:24

从angular Animations docs

Angular动画建立在标准的Web animations API之上,并在支持它的浏览器上本地运行。对于其他浏览器,需要polyfill。从GitHub获取web-animations.min.js并将其添加到您的页面。

你可以在这里看到支持它的浏览器:http://caniuse.com/#feat=web-animation

对于所有其他浏览器(包括Safari),请下载并安装polyfill

editOn如何在angular中安装polyfill请参阅this answer

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40115138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档