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控制器用来处理用户交互的部分.
随机推荐
- UVa 10602 - Editor Nottoobad
题目大意:有一个编辑器,它有两种命令,“重复上一个单词” 和 “删除前一个字母”,给出一系列字符串,求最少的敲击键盘的次数. 题目中强调第一个敲的单词必须是给的第一个单词,于是就考虑按照单词与第一个单 ...
- composer 安装和修改中国镜像
参考:http://docs.phpcomposer.com/00-intro.html#Using-Composer http://www.phpcomposer.com/ 下载安装 下载并且运行 ...
- 字符集 ISO-8859-1(3)
详细见 http://www.w3school.com.cn/tags/html_ref_urlencode.html
- Linux下配置Apache最大连接数
最近有博友发现我的博客经常http 503,博客负载不大,应该不会出现负载问题,很有可能就是Apache最大连接数原因,Apache默认支持150个连接.1.先要修改最大连接数,必须了解Apache的 ...
- jQuery原型技术分解
jQuery原型技术分解 起源----原型继承 用户过javascript的都会明白,在javascript脚本中到处都是 函数,函数可以归置代码段,把相对独立的功能封闭在一个函数包中.函数也可以实现 ...
- Carthage - 一个简单、去集中化的Cocoa依赖管理器
作为一名新时代的90后猿 在swift大势所趋的时候 怎能不会Carthage 配置它其实很简单 下面我们一步一步来 (1)打开你的终端 输入 brew update brew install c ...
- lepus3.7 天兔监控安装手册 CentOS6.5+mysql5.6
lepus3.7 天兔监控安装配置手册 CentOS6.5+mysql5.6 整体环境 192.168.1.250为监控机 192.168.1.248为被监控机 安装LAMP环境 [root@HE3~ ...
- spring mvc 注解入门示例
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...
- I/O模型浅析
引入 首先来说一下进程: 进程在就是一段执行中的代码,他是由一条条指令和数据组成的一个具有生命周期的有头有尾的实体. 进程根据权限大体上可以分为两类:用户进程 和 内核进程. 这两者的主要区别在于权限 ...
- 应用程序初次运行数据库配置小程序(Java版)
应用程序初始化数据库配置小程序 之前写过一个Java版的信息管理系统,但部署系统的时候还需要手动的去配置数据库和导入一些初始化的数据才能让系统运行起来,所以我在想是不是可以写一个小程序在系统初次运行的 ...