[Angular] Two ways to create Angular Animation, using animation() or using state()
We have two blocks to show to difference ways to do animation in Angular:
<button (click)="toggleState()">Toggle</button> <div style="display: flex; align-items: center; align-content: space-between;"> <section [@heightZeroFull] *ngIf="state === 'active'" style="width: 200px; height: 200px; background: black;">
</section> <section [@heightState]="state" style="width: 200px; height: 200px; background: blue;"></section>
</div>
heightZeroFull using animation(). heightState using state().
The way to control the state is:
state = 'active';
toggleState() {
if (this.state === 'inactive') {
this.state = 'active';
} else {
this.state = 'inactive';
}
}
In the component, we define 'animations':
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
animations: [
heightZeroFull({duration: '500ms'}),
heightState({height: '200px', duration: '500ms'})
]
})
We pass in params, so it is more configurable.
Animation.ts:
import {animation, style, animate, trigger, transition, useAnimation, state} from '@angular/animations';
/*
* DSL
* */
const heightStart = animation([
style({
height:
}),
animate(
"{{duration}} ease-in",
style({
height: '*'
})
)
]);
const heightEnd = animation([
animate(
"{{duration}} ease-out",
style({
height:
})
)
]);
/*
* Transition
* */
// Using animation
export const heightZeroFull = (params) => {
return trigger('heightZeroFull', [
transition(':enter', useAnimation(heightStart, {params})),
transition(':leave', useAnimation(heightEnd, {params}))
]);
};
// Using state
export const heightState = (params) => {
return trigger('heightState', [
state('inactive', style({
height:
})),
state('active', style({
height: params.height
})),
transition('inactive => active', animate(`${params.duration} ease-in`)),
transition('active => inactive', animate(`${params.duration} ease-out`))
]);
};
[Angular] Two ways to create Angular Animation, using animation() or using state()的更多相关文章
- angular源码分析:angular的整个加载流程
在前面,我们讲了angular的目录结构.JQLite以及依赖注入的实现,在这一期中我们将重点分析angular的整个框架的加载流程. 一.从源代码的编译顺序开始 下面是我们在目录结构哪一期理出的an ...
- angular源码分析:angular中各种常用函数,比较省代码的各种小技巧
angular的工具函数 在angular的API文档中,在最前面就是讲的就是angular的工具函数,下面列出来 angular.bind //用户将函数和对象绑定在一起,返回一个新的函数 angu ...
- angular源码分析:angular中的依赖注入式如何实现的
一.准备 angular的源码一份,我这里使用的是v1.4.7.源码的获取,请参考我另一篇博文:angular源码分析:angular源代码的获取与编译环境安装 二.什么是依赖注入 据我所知,依赖注入 ...
- [Angular] Use ngx-build-plus to compile Angular Elements
We can treat Angular Element as each standlone lib and compile each Angular element spreatly. Tool w ...
- angular源码分析:angular中脏活累活的承担者之$interpolate
一.首先抛出两个问题 问题一:在angular中我们绑定数据最基本的方式是用两个大括号将$scope的变量包裹起来,那么如果想将大括号换成其他什么符号,比如换成[{与}],可不可以呢,如果可以在哪里配 ...
- angular源码分析:angular中入境检察官$sce
一.ng-bing-html指令问题 需求:我需要将一个变量$scope.x = '<a href="http://www.cnblogs.com/web2-developer/&qu ...
- angular的跨域(angular百度下拉提示模拟)和angular选项卡
1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...
- angular源码分析:angular中jqLite的实现——你可以丢掉jQuery了
一.从function JQLite(element)函数开始. function JQLite(element) { if (element instanceof JQLite) { //情况1 r ...
- angular源码分析:angular的源代码目录结构说明
一.读源码,是选择"编译合并后"的呢还是"编译前的"呢? 有朋友说,读angular源码,直接看编译后的,多好,不用管模块间的关系,从上往下读就好了.但是在我看 ...
随机推荐
- scaleType-模拟按钮加文字整天点击效果
经常碰到这种情况,就是一个按钮下面有文字,我们点击按钮的时候,按钮跟文字的背景都是同时变化的.我们看下下面的效果 点击以后如下 如果想要实现这个方法,网上有很多的方法,主要就是自定义控件,或者是使用t ...
- POJ 2323 贪心
题意: 思路: 贪 贪 贪 如果当前的c>之前的c+s 那么之前的合适 一直贪下去就好了 //By SiriusRen #include <cstdio> #include < ...
- javap 命令 反编译代码
javap 命令 javap -c classname 一个好的分析class二进制文件的 链接 http://blog.csdn.net/pwlazy/article/details/7954169
- Kinect 开发 —— 开发前的准备工作
Kinect SDK v1.5 支持托管语言和非托管语言 Xbox360的游戏是基于Xbox360开发工具包 (XDK)开发的,Xbox 360和Windows是两个完全不同的系统架构.使用Kinec ...
- mkfs---创建Linux文件系统
[root@xiaolizi ~]# mkfsmkfs mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs ...
- HUD——T 3836 Equivalent Sets
http://acm.hdu.edu.cn/showproblem.php?pid=3836 Time Limit: 12000/4000 MS (Java/Others) Memory Lim ...
- pat(A) 2-06. 数列求和(模拟摆竖式相加)
1.链接:http://www.patest.cn/contests/ds/2-06 2.思路:模拟摆竖式相加,因为同样位置上的数字同样,那么同一位上的加法就能够用乘法来表示 3.代码: #inclu ...
- 制作U盘启动盘将Ubuntu 12.04升级为14.04的方法
1 介绍 在周六的下午,我决定想高速浏览一下书籍[1].看看这个关于Ubuntu的圣经到底在讲什么东东. 感觉讲的不错,当我看到介绍文件标记语言-TeX和LaTeX的时候,该书作者推荐在Ubuntu上 ...
- iOS动画之模拟音量振动条
音量振动条 效果图: 假设实现? 创建3个layer.按顺序播放y轴缩放动画 利用CAReplicatorLayer实现 1.什么是CAReplicatorLayer? 一种能够复制自己子层的laye ...
- 关于使用toFixed()函数时报错"toFixed() is not a function"的问题
toFixed()函数只有数字类型的参数才可使用,字符串类型的参数需用parseFloat或者parseInt转换后再使用