angular 2 animate 笔记
好久没有在这里写点笔记了。时隔已久,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 可以得到 fromState,toState和totalTime
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 笔记的更多相关文章
- Angular快速学习笔记(2) -- 架构
0. angular 与angular js angular 1.0 google改名为Angular js 新版本的,2.0以上的,继续叫angular,但是除了名字还叫angular,已经是一个全 ...
- Angular 快速学习笔记(1) -- 官方示例要点
创建组件 ng generate component heroes {{ hero.name }} {{}}语法绑定数据 管道pipe 格式化数据 <h2>{{ hero.name | u ...
- Angular【学习笔记】
1.angular入门网站 感谢@菜鸟教程:http://www.runoob.com/angularjs/angularjs-tutorial.html 学习笔记:
- Angular JS 学习笔记(自定义服务:factory,Promise 模式异步请求查询:$http,过滤器用法filter,指令:directive)
刚学没多久,作了一个小项目APP,微信企业号开发与微信服务号的开发,使用的是AngularJS开发,目前项目1.0版本已经完结,但是项目纯粹为了赶工,并没有发挥AngularJS的最大作用,这几天项目 ...
- Angular源代码学习笔记-原创
时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...
- Angular 4 学习笔记 从入门到实战 打造在线竞拍网站 基础知识 快速入门 个人感悟
最近搞到手了一部Angular4的视频教程,这几天正好有时间变学了一下,可以用来做一些前后端分离的网站,也可以直接去打包web app. 环境&版本信息声明 运行ng -v @angular/ ...
- Phonegap集成angular/bootstrap/animate.css教程
1,phonegap集成angular 按照这篇文档的步骤:http://projectpoppycock.com/angularjs-phonegap-and-angular-seed-lets-g ...
- Angular.JS学习笔记——1
内容来自:http://www.runoob.com/angularjs/angularjs-intro.html AngularJS 是一个 JavaScript 框架.它是一个以 JavaScri ...
- angular.js学习笔记之一
angular也是一个MVC框架,其中M即model模型表示服务器,V即view视图代表html代码,C即control控制器用来处理用户交互的部分.
随机推荐
- Oracle的一些命令
sqlldr: 一般用于导入以任何后缀结束的文件,我这次就是因为要导入一张以.20160101为后缀的文件,当初简直束手无策 结合input.ctl使用,可以在DOS下使用,可以对一张表导入数十万,百 ...
- delphi公用函数
{*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 } ...
- VMware虚拟机出现Reason: Failed to lock the file
打开VMware出现Cannot open the disk *.vmdk or one of the snapshot disks it depends on.Reason: Failed to l ...
- centos下修改hostname,ip,netmask,gateway,dns
http://itlab.idcquan.com/linux/set/917191.html http://jingyan.baidu.com/article/e4d08ffdd417660fd3f6 ...
- eclipse jsp html 格式化 format
eclipse jsp html 格式化 format http://blog.csdn.net/hexin373/article/details/7677250
- FMS+NGINX打造高带宽利用率的流媒体(音频+视频)环境
fms自身已经拥有了httpd,用来给客户端访问用,例如通过http的音频播放.众所周知,非专业的httpd自然有不专业之处,例如我遇到的情况就是经常http服务假死,或者在访问量庞大的时候会无缘无故 ...
- jQuery获取、设置title的值
获取值:var t = $(document).attr('title'); 设置值:$(document).attr('title','value');
- web下c#用jquery.tmpl.min.js插件实现分页查询_yginuo
背景:webform或者mvc下实现插件快速分页 ps:我这里用的mvc开发的,数据库连接.用的ADO.NET实体数据模型 此案例下载地址(内含需要用到的一个插件与数据库):http://downlo ...
- python yield generator 详解
本文将由浅入深详细介绍yield以及generator,包括以下内容:什么generator,生成generator的方法,generator的特点,generator基础及高级应用场景,genera ...
- linux命令行模式下对FTP服务器进行文件上传下载
参考源:点击这里查看 1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码 ...