angular2
中使用自带的动画
一、在组件中创建一个动画
import {Component,OnInit,style,trigger,state,transition,animate,keyframes} from '@angular/core';
@Component({
selector: 'app-page1',
templateUrl: './page1.component.html',
styleUrls: ['./page1.component.css'],
animations:[
trigger("动画名称",[
state("状态名称",style({
transform:"scale(1)"
})),
state("active",style({
transform:"scale(1.5)"
})),
transition("inactive=>active",animate("100ms ease-in")),
transition("active=>inactive",animate("100ms ease-out")),
])
]
})
二、在html
页面中使用动画
<div class="box" [@动画名称]="动画句柄名称" (mouseenter)="toggleLoginState(true)" (mouseleave)="toggleLoginState(false)"></div>
三、操作动画
export class Page1Component implements OnInit {
private loginBtnState:string = "inactive";
constructor() { }
ngOnInit() {
}
toggleLoginState(state:boolean){
this.loginBtnState = state ? "active":"inactive";
}
}