【问题标题】:Angular 2 triggering animationsAngular 2 触发动画
【发布时间】:2017-11-18 05:04:13
【问题描述】:

按照此文档here,我正在尝试将一些动画放入我的应用程序中,但我在理解动画触发器时遇到了一些问题。

HTML 组件

<div class="navbar navbar-default navbar-fixed-top">
    <ul class="nav navbar-nav">
        <li>
            <span (click)="open()" class="glyphicons glyphicons-show-lines">open</span>
        </li>
    </ul>
</div>
<div class="vertical-menu" @verticalOpen="openOrClose">
    <div class="list-group table-of-contents">
        <a class="list-group-item" [routerLink]="['/login']" routerLinkActive="active">Login</a>
        <a class="list-group-item" [routerLink]="['/personalArea routerLinkActive="active">Personal Area</a>
    </div>
</div>

ts 文件

@Component({
   selector:'menu-bar',
   templateUrl:'app/components/menubar/menubar.component.html',
   styleUrls:['app/components/menubar/menubar.component.css'],
   directives:[ROUTER_DIRECTIVES],
   animations:[
       trigger('verticalOpen',[
           state('inactive',style({
               left: '-115px',
               transform:'scale(1)',
               backgroundColor:'red'
           })),
           state('active',style({
               left: '0px',
               transform:'scale(1.3)'
           })),
           transition('active => inactive', animate('100ms ease-in')),
           transition('inactive => active', animate('100ms ease-out'))
       ])
   ]
})
export class MenuBar{
    closeOrOpen:string;
    open(){
        if(this.closeOrOpen=='inactive'){
            this.closeOrOpen='active'
        }
        else if(this.closeOrOpen=='active'){
            this.closeOrOpen='inactive'    
        }
        else{
            this.closeOrOpen='inactive'
        }
        console.log(this.closeOrOpen)
    }
}

所以我想要做的是使用按钮触发样式更改,但是当我单击时没有任何变化。对我来说看代码没有错误,是真的吗?我错过了什么?

【问题讨论】:

    标签: angular typescript angular-animations


    【解决方案1】:

    在您的模板中,您有:

    @verticalOpen="openOrClose" 
    

    因此,在您的 open 方法中,您需要切换 openOrClose 属性而不是 closeOrOpen

    【讨论】:

      猜你喜欢
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 2018-08-27
      • 2017-03-11
      相关资源
      最近更新 更多