Skip to content

Commit 82bbc47

Browse files
committed
docs(readme): add info about 'start' and 'done' callbacks
#60
1 parent 638cc4a commit 82bbc47

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![npm version](https://badge.fury.io/js/angular-animations.svg)](https://www.npmjs.com/package/angular-animations)
44
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)
55
[![Gitter chat](https://badges.gitter.im/angular-animations.png)](https://gitter.im/angular-animations/Lobby)
6+
[![Code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
67

78
Easy, Reusable Animation Utility library for Angular Apps.
89

@@ -11,7 +12,8 @@ Angular Animations utility library is a collection of reusable and parametrized
1112
### Quick links
1213

1314
[Demo](https://filipows.github.io/angular-animations/) |
14-
[StackBlitz Template](https://stackblitz.com/edit/angular-animations-lib-demo)
15+
[StackBlitz Demo](https://stackblitz.com/edit/angular-animations-lib-demo) |
16+
[StackBlitz Base Template](https://stackblitz.com/edit/angular-animations-lib-base-template)
1517

1618
## Getting Started
1719

@@ -154,12 +156,66 @@ In a template (providing option for dynamic changes):
154156
<div *ngIf="CONDITION" [@enter]="{ value: '', params: { duration: 300, delay: 100, translate: '40px } }" [@leave]></div>
155157
```
156158
157-
With parameters in a template, we can for ex achieve staggering animations:
159+
With parameters in a template, we can for example achieve staggering animations:
158160
159161
```html
160162
<div *ngFor="let i of [1,2,3]" [@enter]="{ value: '', params: { delay: i * 100 } }"></div>
161163
```
162164
165+
### Animation Callbacks
166+
167+
Each animation supports `start` and `done` callbacks to setup hook methods that get called at the start or end of animations.
168+
We can add callbacks with the syntax `(@trigger.start)` or `(@trigger.done)`, where `trigger` is the name of the animation trigger/anchor being used.
169+
170+
```html
171+
<div [@fadeIn]="animationState" (@fadeIn.start)="animStart($event)" (@fadeIn.done)="animDone($event)"></div>
172+
```
173+
174+
The callbacks receive an `AnimationEvent` that contains the following properties: `fromState` `phaseName`("start" or "done"), `toState` and `totalTime`
175+
176+
```ts
177+
import { AnimationEvent } from '@angular/animations';
178+
179+
//...
180+
181+
animStart(event: AnimationEvent) {
182+
console.log('Animation Started', event);
183+
}
184+
185+
animDone(event: AnimationEvent) {
186+
console.log('Animation Ended', event);
187+
}
188+
```
189+
190+
You can find more information about Animation callbacks in the [Angular docs](https://angular.io/guide/transition-and-triggers#animation-callbacks)
191+
192+
#### Loop animation
193+
194+
You can achieve looped animation by using `done` callback. Define a variable that triggers animation and toggle it when animation done callback is called:
195+
196+
```html
197+
<div [@bounce]="animState" (@bounce.done)="animDone()"></div>
198+
```
199+
200+
and in the component:
201+
202+
```ts
203+
animState = false;
204+
205+
animDone() {
206+
this.animState = !this.animState
207+
}
208+
```
209+
210+
[Example: simple infinite loop animation](https://stackblitz.com/edit/angular-animations-lib-simple-loop?file=src/app/demo-main/demo-main.component.html) <br />
211+
[Example: repeat animation N times after clicking the button](https://stackblitz.com/edit/angular-animations-lib-simple-loop-repeat-n-times?file=src/app/demo-main/demo-main.component.html)<br />
212+
[Example: repeat animation until certain event occurs](https://stackblitz.com/edit/angular-animations-lib-simple-loop-repeat-until-btn-click?file=src/app/demo-main/demo-main.component.html)
213+
214+
#### Chain animations
215+
216+
You can chain animations (e.g. wait for the first animation to finish before the second one starts) by using the `done` callback.
217+
[Example: OnEnter/OnLeave chained animations](https://stackblitz.com/edit/angular-animations-lib-chained-on-enter?file=src/app/demo-main/demo-main.component.html)
218+
163219
## Available Animations and Parameters
164220
165221
All animations have `duration` and `delay` params.

0 commit comments

Comments
 (0)