ng-animation

1.在组件定义和声明触发器

2.声明state

3.在标签上使用[@state]='state’指明是哪个触发器

4.在标签上定义函数切换state

step1,step2

定义触发器
trigger是个函数  
animations:[cardAnim]
animations这个数组存放animation相关的函数
import { trigger, state, transition, style, animate, keyframes } from '@angular/animations'
export const cardAnim = trigger('card',[
    state('out', style({transform: 'scale(1)', 'box-shadow': 'none'})),
    state('hover', style({transform: 'scale(1.1)','box-shadow': '3px 3px 5px 6px #ccc'})),
    transition('out => hover', animate('100ms ease-in')),
    transition('hover => out', animate('100ms ease-out'))
]);
声明触发器
import { cardAnim } from '../app/anims/card.anim'
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less'],
  animations: [cardAnim]--->函数
})

step3,step4

 <div class="square" [@card]="squareState" (click)="onClick()">
 //@card 这个card 是 trigger的名字
 //squareState是个普通字符串
 //这二者结合在一起,squareState就指向了一个具体的state,决定动画如何展示
 onClick(){
      this.squareState = this.squareState === 'out' ? 'hover' : 'out';
  }

坑的地方:

1.必须在组件animation数组里面声明触发器函数
2.@triggerName
3.squareState aniamtion的某个具体state
4.注意导入相关依赖
//动画组件
import { trigger, state, transition, style, animate, keyframes } from '@angular/animations'
//根组件
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值