Easy, Reusable Animation Utility library for Angular Apps.
Angular Animations utility library is a collection of reusable and parametrized animations build for Angular 4.4.6+ that can be used in a declarative manner. It implements all animations from animate.css (and more). Works both with AOT and JIT compilations.
Demo |StackBlitz Demo |StackBlitz Base Template
Make sure you import BrowserAnimationModule
in your angular app.
npm i @angular/animations@latest --save
Import BrowserAnimationsModule
from @angular/platform-browser/animations
in your root NgModule
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
declarations: [
...
],
imports: [
...
BrowserAnimationsModule
],
})
export class AppModule { }
npm i angular-animations --save
on enter
/ on leave
Animations on enter / on leave are triggered in a moment when element is added to or removed from the dom.Basic example would be with *ngIf
template directive.
Import animation functions that you want to use and add them to animations
in a component decorator:
import { fadeInOnEnterAnimation, fadeOutOnLeaveAnimation } from 'angular-animations';
@Component({
selector: '...',
templateUrl: '...',
styleUrls: ['...'],
animations: [
fadeInOnEnterAnimation(),
fadeOutOnLeaveAnimation()
]
})
and use them in the template:
<div *ngIf="CONDITION" [@fadeInOnEnter] [@fadeOutOnLeave]></div>
These animations take as an input a boolean value. Some animations, like Attention Seekers are triggered depending on the direction
parameter; bidirectional (<=>
) will be triggered by any state change, unidirectional (=>
) will be triggered only when state changes from false to true.
All in
and out
animations are triggered by changes of state from false
to true
. Animations that preserve state, like collapse
or rotate
display default state when the value is false
and transition to end state when the value is true
import { collapseAnimation, rubberBandAnimation } from 'angular-animations';
@Component({
...
animations: [
rubberBandAnimation(),
collapseAnimation(),
]
})
<div [@rubberBand]="rubberState"></div>
<div [@collapse]="collapseState"></div>
All animations are open for customizations. All of them have parameters: duration
and delay
, and if it make sense for an animation, additional ones: translate
, degrees
or scale
.
Parameters can be used either in a component decorator or dynamically in a template.
In a decorator:
@Component({
...
animations: [
fadeInUpOnEnterAnimation({ anchor: 'enter', duration: 1000, delay: 100, translate: '30px' }),
bounceOutDownOnLeaveAnimation({ anchor: 'leave', duration: 500, delay: 200, translate: '40px' })
]
})
<div *ngIf="CONDITION" [@enter] [@leave]></div>
Animations like Attention Seekers can take a direction parameter (cannot be in template)
@Component({
...
animations: [
// triggers when STATE changes from false to true
rubberBandAnimation({anchor: 'rubber', direction: '=>', duration: 500})
]
})
<div [@rubber]="STATE"></div>
In a template (providing option for dynamic changes):
@Component({
...
animations: [
fadeInUpOnEnterAnimation({ anchor: 'enter'),
]
})
<div *ngIf="CONDITION" [@enter]="{ value: '', params: { duration: 300, delay: 0, translate: '30px' } }" [@leave]></div>
<div *ngIf="CONDITION" [@enter]="{ value: '', params: { duration: 300, delay: 100, translate: '40px } }" [@leave]></div>
With parameters in a template, we can for example achieve staggering animations:
<div *ngFor="let i of [1,2,3]" [@enter]="{ value: '', params: { delay: i * 100 } }"></div>
Each animation supports start
and done
callbacks to setup hook methods that get called at the start or end of animations.We can add callbacks with the syntax (@trigger.start)
or (@trigger.done)
, where trigger
is the name of the animation trigger/anchor being used.
<div [@fadeIn]="animationState" (@fadeIn.start)="animStart($event)" (@fadeIn.done)="animDone($event)"></div>
The callbacks receive an AnimationEvent
that contains the following properties: fromState
phaseName
("start" or "done"), toState
and totalTime
import { AnimationEvent } from '@angular/animations';
//...
animStart(event: AnimationEvent) {
console.log('Animation Started', event);
}
animDone(event: AnimationEvent) {
console.log('Animation Ended', event);
}
You can find more information about Animation callbacks in the Angular docs
You can achieve looped animation by using done
callback. Define a variable that triggers animation and toggle it when animation done callback is called:
<div [@bounce]="animState" (@bounce.done)="animDone()"></div>
and in the component:
animState = false;
animDone() {
this.animState = !this.animState
}
Example: simple infinite loop animation
Example: repeat animation N times after clicking the button
Example: repeat animation until certain event occurs
You can chain animations (e.g. wait for the first animation to finish before the second one starts) by using the done
callback.Example: OnEnter/OnLeave chained animations
All animations have duration
and delay
params.
Animation | Default Anchor | OnEnter/OnLeave | Additional Params | |
---|---|---|---|---|
Attention Seekers | ||||
bounce | [@bounce] |
[@bounceOnEnter] |
||
flash | [@flash] |
[@flashOnEnter] |
||
pulse | [@pulse] |
[@pulseOnEnter] |
scale (default: 1.05) |
|
rubberBand | [@rubberBand] |
[@rubberBandOnEnter] |
||
shake | [@shake] |
[@shakeOnEnter] |
translate (default: '10px') |
|
swing | [@swing] |
[@swingOnEnter] |
||
tada | [@tada] |
[@tadaOnEnter] |
||
wobble | [@wobble] |
[@wobbleOnEnter] |
||
jello | [@jello] |
[@jelloOnEnter] |
||
heartBeat | [@heartBeat] |
[@heartBeatOnEnter] |
scale (default: 1.3) |
|
headShake | [@headShake] |
[@headShakeOnEnter] |
||
Bouncing entrances | ||||
bounceIn | [@bounceIn] |
[@bounceInOnEnter] |
||
bounceInDown | [@bounceInDown] |
[@bounceInDownOnEnter] |
translate (default: '3000px') |
|
bounceInLeft | [@bounceInLeft] |
[@bounceInLeftOnEnter] |
translate (default: '3000px') |
|
bounceInRight | [@bounceInRight] |
[@bounceInRightOnEnter] |
translate (default: '3000px') |
|
bounceInUp | [@bounceInUp] |
[@bounceInUpOnEnter] |
translate (default: '3000px') |
|
Bouncing exits | ||||
bounceOut | [@bounceOut] |
[@bounceOutOnLeave] |
||
bounceOutDown | [@bounceOutDown] |
[@bounceOutDownOnLeave] |
translate (default: '2000px') |
|
bounceOutLeft | [@bounceOutLeft] |
[@bounceOutLeftOnLeave] |
translate (default: '2000px') |
|
bounceOutRight | [@bounceOutRight] |
[@bounceOutRightOnLeave] |
translate (default: '2000px') |
|
bounceOutUp | [@bounceOutUp] |
[@bounceOutUpOnLeave] |
translate (default: '2000px') |
|
Fading entrances | ||||
fadeIn | [@fadeIn] |
[@fadeInOnEnter] |
||
fadeInDown | [@fadeInDown] |
[@fadeInDownOnEnter] |
translate (default: '100%') |
|
fadeInDownBig | [@fadeInDownBig] |
[@fadeInDownBigOnEnter] |
translate (default: '2000px') |
|
fadeInLeft | [@fadeInLeft] |
[@fadeInLeftOnEnter] |
translate (default: '100%') |
|
fadeInLeftBig | [@fadeInLeftBig] |
[@fadeInLeftBigOnEnter] |
translate (default: '2000px') |
|
fadeInRight | [@fadeInRight] |
[@fadeInRightOnEnter] |
translate (default: '100%') |
|
fadeInRightBig | [@fadeInRightBig] |
[@fadeInRightBigOnEnter] |
translate (default: '2000px') |
|
fadeInUp | [@fadeInUp] |
[@fadeInUpOnEnter] |
translate (default: '100%') |
|
fadeInUpBig | [@fadeInUpBig] |
[@fadeInUpBigOnEnter] |
translate (default: '2000px') |
|
Fading exits | ||||
fadeOut | [@fadeOut] |
[@fadeOutOnLeave] |
||
fadeOutDown | [@fadeOutDown] |
[@fadeOutDownOnLeave] |
translate (default: '100%') |
|
fadeOutDownBig | [@fadeOutDownBig] |
[@fadeOutDownBigOnLeave] |
translate (default: '2000px') |
|
fadeOutLeft | [@fadeOutLeft] |
[@fadeOutLeftOnLeave] |
translate (default: '100%') |
|
fadeOutLeftBig | [@fadeOutLeftBig] |
[@fadeOutLeftBigOnLeave] |
translate (default: '2000px') |
|
fadeOutRight | [@fadeOutRight] |
[@fadeOutRightOnLeave] |
translate (default: '100%') |
|
fadeOutRightBig | [@fadeOutRightBig] |
[@fadeOutRightBigOnLeave] |
translate (default: '2000px') |
|
fadeOutUp | [@fadeOutUp] |
[@fadeOutUpOnLeave] |
translate (default: '100%') |
|
fadeOutUpBig | [@fadeOutUpBig] |
[@fadeOutUpBigOnLeave] |
translate (default: '2000px') |
|
Flippers | ||||
flip | [@flip] |
[@flipOnEnter] |
||
flipInX | [@flipInX] |
[@flipInXOnEnter] |
degrees (default: 90) |
|
flipInY | [@flipInY] |
[@flipInYOnEnter] |
degrees (default: 90) |
|
flipOutX | [@flipOutX] |
[@flipOutXOnLeave] |
degrees (default: 90) |
|
flipOutY | [@flipOutY] |
[@flipOutYOnLeave] |
degrees (default: 90) |
|
Light speed | ||||
lightSpeedIn | [@lightSpeedIn] |
[@lightSpeedInOnEnter] |
translate (default: '100%') |
|
lightSpeedOut | [@lightSpeedOut] |
[@lightSpeedOutOnLeave] |
translate (default: '100%') |
|
Rotating entrances | ||||
rotateIn | [@rotateIn] |
[@rotateInOnEnter] |
degrees (default: -200) |
|
rotateInDownLeft | [@rotateInDownLeft] |
[@rotateInDownLeftOnEnter] |
degrees (default: -45) |
|
rotateInDownRight | [@rotateInDownRight] |
[@rotateInDownRightOnEnter] |
degrees (default: 45) |
|
rotateInUpLeft | [@rotateInUpLeft] |
[@rotateInUpLeftOnEnter] |
degrees (default: 45) |
|
rotateInUpRight | [@rotateInUpRight] |
[@rotateInUpRightOnEnter] |
degrees (default: -90) |
|
Rotating exits | ||||
rotateOut | [@rotateOut] |
[@rotateOutOnLeave] |
degrees (default: 200) |
|
rotateOutDownLeft | [@rotateOutDownLeft] |
[@rotateOutDownLeftOnLeave] |
degrees (default: 45) |
|
rotateOutDownRight | [@rotateOutDownRight] |
[@rotateOutDownRightOnLeave] |
degrees (default: -45) |
|
rotateOutUpLeft | [@rotateOutUpLeft] |
[@rotateOutUpLeftOnLeave] |
degrees (default: -45) |
|
rotateOutUpRight | [@rotateOutUpRight] |
[@rotateOutUpRightOnLeave] |
degrees (default: -90) |
|
Sliding entrances | ||||
slideInUp | [@slideInUp] |
[@slideInUpOnEnter] |
translate (default: '100%') |
|
slideInDown | [@slideInDown] |
[@slideInDownOnEnter] |
translate (default: '100%') |
|
slideInLeft | [@slideInLeft] |
[@slideInLeftOnEnter] |
translate (default: '100%') |
|
slideInRight | [@slideInRight] |
[@slideInRightOnEnter] |
translate (default: '100%') |
|
Sliding exits | ||||
slideOutUp | [@slideOutUp] |
[@slideOutUpOnLeave] |
translate (default: '100%') |
|
slideOutDown | [@slideOutDown] |
[@slideOutDownOnLeave] |
translate (default: '100%') |
|
slideOutLeft | [@slideOutLeft] |
[@slideOutLeftOnLeave] |
translate (default: '100%') |
|
slideOutRight | [@slideOutRight] |
[@slideOutRightOnLeave] |
translate (default: '100%') |
|
Zooming entrances | ||||
zoomIn | [@zoomIn] |
[@zoomInOnEnter] |
||
zoomInDown | [@zoomInDown] |
[@zoomInDownOnEnter] |
||
zoomInLeft | [@zoomInLeft] |
[@zoomInLeftOnEnter] |
||
zoomInRight | [@zoomInRight] |
[@zoomInRightOnEnter] |
||
zoomInUp | [@zoomInUp] |
[@zoomInUpOnEnter] |
||
Zooming exits | ||||
zoomOut | [@zoomOut] |
[@zoomOutOnLeave] |
||
zoomOutDown | [@zoomOutDown] |
[@zoomOutDownOnLeave] |
||
zoomOutLeft | [@zoomOutLeft] |
[@zoomOutLeftOnLeave] |
||
zoomOutRight | [@zoomOutRight] |
[@zoomOutRightOnLeave] |
||
zoomOutUp | [@zoomOutUp] |
[@zoomOutUpOnLeave] |
||
Specials | ||||
hinge | [@hinge] |
[@hingeOnLeave] |
||
jackInTheBox | [@jackInTheBox] |
[@jackInTheBoxOnEnter] |
||
rollIn | [@rollIn] |
[@rollInOnEnter] |
degrees (default: -120), translate (default: '-100%') |
|
rollOut | [@rollOut] |
[@rollOutOnLeave] |
degrees (default: 120), translate (default: '100%') |
|
Other | ||||
collapse | [@collapse] [@collapseHorizontally] |
[@expandOnEnter] [@collapseOnLeave] [@fadeInExpandOnEnter] [@fadeOutCollapseOnLeave] [@expandRightOnEnter] [@collapseLeftOnLeave] [@fadeInExpandRightOnEnter] [@fadeOutCollapseLeftOnLeave] |
||
rotate | [@rotate] |
- |
degrees (default: 90) |
|
hueRotate | [@hueRotate] |
- |
npm install
npm start
This project is licensed under the MIT License - see the LICENSE file for details
使用方法一(文件形式定义): animations.ts import { animate, AnimationEntryMetadata, state, style, transition, trigger } from '@angular/core'; // Component transition animations export const slideInDownAnimation:
首先说环境,我是 npm 5.6.0,Angular6,windows7 64位 $ npm -version 5.6.0 问题背景:学习Angular有一段时间了,现在想系统的根据官网学习一遍,但在最后一个课程出了问题 官方课程:https://www.angular.cn/tutorial/toh-pt6 问题描述: 在 app.module.ts 添加module失败: import {
在《Angular官方教程第七课HTTP》调试示例出现Cannot find module 'angular-in-memory-web-api' 分析问题 估计是缺少angular-in-memory-web-api依赖包,到工程根目录下的node_modules文件夹下去寻找angular-in-memory-web-api没有找到。 解决问题 查看工程根目录下的package.json,没有
使用方法一(文件形式定义): animations.ts import { animate, AnimationEntryMetadata, state, style, transition, trigger } from '@angular/core'; // Component transition animations export const slideInDownAnimation:
使用angular cli 创建的项目,默认的依赖如下: "dependencies": { "@angular/animations": "~10.1.3", "@angular/common": "~10.1.3", // httpClient; ngClass, ngForOf 等内置指令;DatePipe, JsonPipe 等内置pipe; 等等... "@a
说明: Polyfills(腻子脚本)主要支持低版本浏览器的兼容。 对于腻子脚本Polyfills对补充Internet Explorer的不足和缺失尤其有用,主要针对IE7/8的兼容。 下面常用的腻子脚本示例: html5shiv.js:让IE8 及更低版本的IE 识别section、 article、nav等HTML5元素。 selectivizr:让IE(6/7/8)支持::first-c
Angular-使用ng update命令升级到Angular7.1.4 Angular CLI 是 Angular 的一个命令行工具,可以便捷的执行创建项目、创建文件、测试、打包和发布等任务。 关于 Angular 版本 Angular 2.x及以上统称Angular. Angular 1.x 则称为 AngularJS. Angular 2 发布于 2016年09月14日。 Angular 4
Angular 是一款十分流行且好用的 Web 前端框架,目前由 Google 维护。这个条目收录的是 Angular 2 及其后面的版本。由于官方已将 Angular 2 和之前的版本 Angular.js 分开维护(两者的 GitHub 地址和项目主页皆不相同),所以就有了这个页面。传送门:Angular.js 特性 跨平台 渐进式 Web 应用 借助现代化 Web 平台的力量,交付 app
即将到来的Angular 2框架是使用TypeScript开发的。 因此Angular和TypeScript一起使用非常简单方便。 Angular团队也在其文档里把TypeScript视为一等公民。 正因为这样,你总是可以在Angular 2官网(或Angular 2官网中文版)里查看到最新的结合使用Angular和TypeScript的参考文档。 在这里查看快速上手指南,现在就开始学习吧!
从头开始创建项目 lint你的代码 运行您的单元测试和端到端测试。 Angular 2 CLI目前只在TypeScript中生成框架,稍后还会有其他版本。
这小节内容是译者加的,因为我认为对于新手而言,学习一个框架是有成本的,特别是对于一个不算简单的技术来说,我希望这篇教程是对新手友好的,所以我首先要让你放心的将时间和精力投入到Angular2 中。那我们先不谈技术细节,先用数据说话。 这里我多说一句,最近看一些文章中谷歌趋势截图,大都没有把范围限定在“编程”上。图中可以看出Vue2非常少,所以在下面比较中不再单独统计。 教程数量 这里我选取的主要是
我们已经在Highcharts Configuration Syntax一章中看到了用于绘制图表的配置 。 下面给出角度计图表的示例。 配置 (Configurations) 现在让我们看一下所采取的其他配置/步骤。 chart.type 将图表类型配置为基于计量。 将类型设置为“规格”。 var chart = { type: 'guage' }; pane 此类型仅适用于极坐标图和角度
角度计图表用于绘制仪表/仪表类型图表。 在本节中,我们将讨论不同类型的角度计图表。 Sr.No. 图表类型和描述 1 角度计 角度表。 2 实心仪表 实心图表。 3 Clock 时钟。 4 带双轴的仪表 带双轴的仪表图。 5 VU表 VU表图表。