Skip to content

Commit c5e1446

Browse files
committed
Add trigger animation question
1 parent 211a44a commit c5e1446

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

README.md

+39-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
|248| [What are the lifecycle hooks of a zone?](#what-are-the-lifecycle-hooks-of-a-zone)|
257257
|249| [Which are the methods of NgZone used to control change detection?](#which-are-the-methods-of-ngzone-used-to-control-change-detection)|
258258
|250| [How do you change the settings of zonejs?](#how-do-you-change-the-settings-of-zonejs)|
259-
|251| [?](#)|
259+
|251| [How do you trigger an animation?](#how-do-you-trigger-an-animation)|
260260

261261

262262
1. ### What is Angular Framework?
@@ -3746,6 +3746,43 @@
37463746
```
37473747
**[⬆ Back to Top](#table-of-contents)**
37483748
3749-
251. ### ?
3749+
251. ### How do you trigger an animation?
3750+
Angular provides a `trigger()` function for animation in order to collect the states and transitions with a specific animation name, so that you can attach it to the triggering element in the HTML template. This function watch for changes and trigger initiates the actions when a change occurs.
3751+
For example, let's create trigger named `upDown`, and attach it to the button element.
3752+
```js
3753+
content_copy
3754+
@Component({
3755+
selector: 'app-up-down',
3756+
animations: [
3757+
trigger('upDown', [
3758+
state('up', style({
3759+
height: '200px',
3760+
opacity: 1,
3761+
backgroundColor: 'yellow'
3762+
})),
3763+
state('down', style({
3764+
height: '100px',
3765+
opacity: 0.5,
3766+
backgroundColor: 'green'
3767+
})),
3768+
transition('up => down', [
3769+
animate('1s')
3770+
]),
3771+
transition('down => up', [
3772+
animate('0.5s')
3773+
]),
3774+
]),
3775+
],
3776+
templateUrl: 'up-down.component.html',
3777+
styleUrls: ['up-down.component.css']
3778+
})
3779+
export class UpDownComponent {
3780+
isUp = true;
3781+
3782+
toggle() {
3783+
this.isUp = !this.isUp;
3784+
}
3785+
3786+
```
37503787
37513788
**[⬆ Back to Top](#table-of-contents)**

0 commit comments

Comments
 (0)