好久没有在这里写点笔记了。时隔已久,angular1 去 angular2 咯

笔记来源https://angular.cn/docs/ts/latest/guide/animations.html

动画基于这标准:https://w3c.github.io/web-animations/

以下是基本设置

template: `
<button (click)="heroState = 'active'">enter</button>
<button (click)="heroState = null">leave</button>
<button (click)="changeAnimate()">animate</button>
<div *ngIf="heroState" [@heroState]="heroState"
(@heroState.start)="animationStarted($event)"
(@heroState.done)="animationDone($event)"
style="width:100px; height:100px;">example</div>
{{heroState}}
`,
animations: [
trigger('heroState', [
state('inactive', style({
backgroundColor: '#eee',
transform: 'scale(1)'
})),
state('active', style({
backgroundColor: '#cfd8dc',
transform: 'scale(1.1)'
})),
transition('inactive => active', animate('100ms ease-in')),
transition('active => inactive', animate('100ms ease-out'))
])
]

在animate 中,需要理解几样东西就能明白真个笔记。

1. @trigger (绑定elem)
2. 状态 (通过状态转换改变style)
3. 过渡 (动画)

状态与过渡 :state 是状态,表明样式。过渡是动画,声明某个状态去到某个状态

state('inactive', style({
backgroundColor: '#eee',
transform: 'scale(1)'
})),
state('active', style({
backgroundColor: '#cfd8dc',
transform: 'scale(1.1)'
})),
transition('inactive => active', animate('100ms ease-in')),
transition('active => inactive', animate('100ms ease-out'))

合拼过渡

transition('inactive <=> active', animate('100ms ease-out'))

转换不保留样式:在过渡添加style,意思是当状态转换时,会使用指定样式,接着执行动画,结束后移除样式

transition('inactive => active', [
style({
backgroundColor: '#cfd8dc',
transform: 'scale(1.3)'
}),
animate('80ms ease-in', style({
backgroundColor: '#eee',
transform: 'scale(1)'
}))
]),

通配符*,进场,出场 : 都是状态转换的方式

    transition('inactive => *', [
style({transform: 'translateX(-100%)'}),
animate(100)
]) transition('* => inactive', [
animate(100, style({transform: 'translateX(100%)'}))
]) transition('* => void', [ //:leave 省略写法
animate(100, style({transform: 'translateX(100%)'}))
]) transition('void => *', [ //:enter 省略写法
animate(100, style({transform: 'translateX(100%)'}))
])

动画变量 : duration, delay,缓动(easing)函数

animate('2000ms 10 ease-in', style({
backgroundColor: '#f00',
transform: 'translateX(100%)'
})),

高级写法:keyframe (css3 原理)

      animate(300, keyframes([
style({opacity: 0, transform: 'translateX(-100%)', offset: 0}),
style({opacity: 1, transform: 'translateX(15px)', offset: 0.3}),
style({opacity: 1, transform: 'translateX(0)', offset: 1.0})
]))

组合animate : 处理混合动画

      group([
animate('0.3s 0.1s ease', style({
transform: 'translateX(0)',
width: 120
})),
animate('0.3s ease', style({
opacity: 1
}))
])

回调 : $event 可以得到 fromStatetoStatetotalTime

template: `
<ul>
<li *ngFor="let hero of heroes"
(@flyInOut.start)="animationStarted($event)"
(@flyInOut.done)="animationDone($event)"
[@flyInOut]="'in'">
{{hero.name}}
</li>
</ul>
`,

  

angular 2 animate 笔记的更多相关文章

  1. Angular快速学习笔记(2) -- 架构

    0. angular 与angular js angular 1.0 google改名为Angular js 新版本的,2.0以上的,继续叫angular,但是除了名字还叫angular,已经是一个全 ...

  2. Angular 快速学习笔记(1) -- 官方示例要点

    创建组件 ng generate component heroes {{ hero.name }} {{}}语法绑定数据 管道pipe 格式化数据 <h2>{{ hero.name | u ...

  3. Angular【学习笔记】

    1.angular入门网站 感谢@菜鸟教程:http://www.runoob.com/angularjs/angularjs-tutorial.html 学习笔记:

  4. Angular JS 学习笔记(自定义服务:factory,Promise 模式异步请求查询:$http,过滤器用法filter,指令:directive)

    刚学没多久,作了一个小项目APP,微信企业号开发与微信服务号的开发,使用的是AngularJS开发,目前项目1.0版本已经完结,但是项目纯粹为了赶工,并没有发挥AngularJS的最大作用,这几天项目 ...

  5. Angular源代码学习笔记-原创

    时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...

  6. Angular 4 学习笔记 从入门到实战 打造在线竞拍网站 基础知识 快速入门 个人感悟

    最近搞到手了一部Angular4的视频教程,这几天正好有时间变学了一下,可以用来做一些前后端分离的网站,也可以直接去打包web app. 环境&版本信息声明 运行ng -v @angular/ ...

  7. Phonegap集成angular/bootstrap/animate.css教程

    1,phonegap集成angular 按照这篇文档的步骤:http://projectpoppycock.com/angularjs-phonegap-and-angular-seed-lets-g ...

  8. Angular.JS学习笔记——1

    内容来自:http://www.runoob.com/angularjs/angularjs-intro.html AngularJS 是一个 JavaScript 框架.它是一个以 JavaScri ...

  9. angular.js学习笔记之一

    angular也是一个MVC框架,其中M即model模型表示服务器,V即view视图代表html代码,C即control控制器用来处理用户交互的部分.

随机推荐

  1. iOS 架构模式

    参考:http://www.cocoachina.com/ios/20160108/14916.html MVC , MVP , MVVM , VIPER

  2. apue chapter 4 文件和目录

    1.文件信息结构体 struct stat{ mode_t st_mode; //file type and permissions ino_t st_ino; //i-node number (se ...

  3. (转载)HTML、CSS、JavaScript、PHP、MySQL 的学习顺序是什么?

    文章转载自 鸟巢 - 技术分享的社区 http://t.runoob.com/question/13 1.HTML.CSS.JavaScript 前端学习三部曲,照着这个顺序依次学习 HTML教程.C ...

  4. iOS 开发 旧版 framework

    0. 参考 http://www.cocoachina.com/ios/20150127/11022.html http://www.cnblogs.com/gcb999/p/3296414.html ...

  5. 译者序(Core Data 应用开发实践指南)

    Core Data 是数据管理框架. 该书用Grocery Dude 购物管理程序来贯穿整个学习过程. 本书共分三个部分: 前7章为基础篇.从基础知识.迁移方式及扩展方式来讲解托管对象模型.怎么用图形 ...

  6. MYSQL 函数复习

    数学函数    ABS(X)    返回X的绝对值    SQRT(x)        返回非负数X的二次方根    MOD(x,y)    返回x被y除后的余数    CEIL(x)         ...

  7. js原生设计模式——6复杂对象的构建—Builder建造者模式

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  8. 在JS中使用COM组件的方法

    首先创建一个COM组件,插入一个双接口Itest,在此接口上实现以下三个方法: STDMETHODIMP Ctest::test(void) //无输入输出参数 { // TODO: 在此添加实现代码 ...

  9. Spring集合配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://ww ...

  10. pytho查找斐波那契序列中的值

    ''' 实现斐波那契序列,查找其中第N个数的值 ''' def FeiBSequence(list,N): length=len(list); i=0; while i<length: if N ...