Skip to content

Commit a9b344f

Browse files
oidacraSplaktar
authored andcommitted
translate: translations for animations guides
Added original English versions and updated Spanish translations for all Angular animations guides, including information about complex sequences, CSS animations, transitions, triggers, reusable animations, route animations, and migration guide.
1 parent 1ed589d commit a9b344f

16 files changed

+2112
-611
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Complex animation sequences
2+
3+
IMPORTANT: The `@angular/animations` package is now deprecated. The Angular team recommends using native CSS with `animate.enter` and `animate.leave` for animations for all new code. Learn more at the new enter and leave [animation guide](guide/animations/enter-and-leave). Also see [Migrating away from Angular's Animations package](guide/animations/migration) to learn how you can start migrating to pure CSS animations in your apps.
4+
5+
So far, we've learned simple animations of single HTML elements.
6+
Angular also lets you animate coordinated sequences, such as an entire grid or list of elements as they enter and leave a page.
7+
You can choose to run multiple animations in parallel, or run discrete animations sequentially, one following another.
8+
9+
The functions that control complex animation sequences are:
10+
11+
| Functions | Details |
12+
|:--- |:--- |
13+
| `query()` | Finds one or more inner HTML elements. |
14+
| `stagger()` | Applies a cascading delay to animations for multiple elements. |
15+
| [`group()`](api/animations/group) | Runs multiple animation steps in parallel. |
16+
| `sequence()` | Runs animation steps one after another. |
17+
18+
## The query() function
19+
20+
Most complex animations rely on the `query()` function to find child elements and apply animations to them, basic examples of such are:
21+
22+
| Examples | Details |
23+
|:--- |:--- |
24+
| `query()` followed by `animate()` | Used to query simple HTML elements and directly apply animations to them. |
25+
| `query()` followed by `animateChild()` | Used to query child elements, which themselves have animations metadata applied to them and trigger such animation \(which would be otherwise be blocked by the current/parent element's animation\). |
26+
27+
The first argument of `query()` is a [css selector](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) string which can also contain the following Angular-specific tokens:
28+
29+
| Tokens | Details |
30+
|:--- |:--- |
31+
| `:enter` <br /> `:leave` | For entering/leaving elements. |
32+
| `:animating` | For elements currently animating. |
33+
| `@*` <br /> `@triggerName` | For elements with any—or a specific—trigger. |
34+
| `:self` | The animating element itself. |
35+
36+
<docs-callout title="Entering and Leaving Elements">
37+
38+
Not all child elements are actually considered as entering/leaving; this can, at times, be counterintuitive and confusing. Please see the [query api docs](api/animations/query#entering-and-leaving-elements) for more information.
39+
40+
You can also see an illustration of this in the animations example \(introduced in the animations [introduction section](guide/legacy-animations#about-this-guide)\) under the Querying tab.
41+
42+
</docs-callout>
43+
44+
## Animate multiple elements using query() and stagger() functions
45+
46+
After having queried child elements via `query()`, the `stagger()` function lets you define a timing gap between each queried item that is animated and thus animates elements with a delay between them.
47+
48+
The following example demonstrates how to use the `query()` and `stagger()` functions to animate a list \(of heroes\) adding each in sequence, with a slight delay, from top to bottom.
49+
50+
* Use `query()` to look for an element entering the page that meets certain criteria
51+
* For each of these elements, use `style()` to set the same initial style for the element.
52+
Make it transparent and use `transform` to move it out of position so that it can slide into place.
53+
54+
* Use `stagger()` to delay each animation by 30 milliseconds
55+
* Animate each element on screen for 0.5 seconds using a custom-defined easing curve, simultaneously fading it in and un-transforming it
56+
57+
<docs-code header="src/app/hero-list-page.component.ts" path="adev/src/content/examples/animations/src/app/hero-list-page.component.ts" visibleRegion="page-animations"/>
58+
59+
## Parallel animation using group() function
60+
61+
You've seen how to add a delay between each successive animation.
62+
But you might also want to configure animations that happen in parallel.
63+
For example, you might want to animate two CSS properties of the same element but use a different `easing` function for each one.
64+
For this, you can use the animation [`group()`](api/animations/group) function.
65+
66+
HELPFUL: The [`group()`](api/animations/group) function is used to group animation *steps*, rather than animated elements.
67+
68+
The following example uses [`group()`](api/animations/group)s on both `:enter` and `:leave` for two different timing configurations, thus applying two independent animations to the same element in parallel.
69+
70+
<docs-code header="src/app/hero-list-groups.component.ts (excerpt)" path="adev/src/content/examples/animations/src/app/hero-list-groups.component.ts" visibleRegion="animationdef"/>
71+
72+
## Sequential vs. parallel animations
73+
74+
Complex animations can have many things happening at once.
75+
But what if you want to create an animation involving several animations happening one after the other? Earlier you used [`group()`](api/animations/group) to run multiple animations all at the same time, in parallel.
76+
77+
A second function called `sequence()` lets you run those same animations one after the other.
78+
Within `sequence()`, the animation steps consist of either `style()` or `animate()` function calls.
79+
80+
* Use `style()` to apply the provided styling data immediately.
81+
* Use `animate()` to apply styling data over a given time interval.
82+
83+
## Filter animation example
84+
85+
Take a look at another animation on the example page.
86+
Under the Filter/Stagger tab, enter some text into the **Search Heroes** text box, such as `Magnet` or `tornado`.
87+
88+
The filter works in real time as you type.
89+
Elements leave the page as you type each new letter and the filter gets progressively stricter.
90+
The heroes list gradually re-enters the page as you delete each letter in the filter box.
91+
92+
The HTML template contains a trigger called `filterAnimation`.
93+
94+
<docs-code header="src/app/hero-list-page.component.html" path="adev/src/content/examples/animations/src/app/hero-list-page.component.html" visibleRegion="filter-animations" language="angular-html"/>
95+
96+
The `filterAnimation` in the component's decorator contains three transitions.
97+
98+
<docs-code header="src/app/hero-list-page.component.ts" path="adev/src/content/examples/animations/src/app/hero-list-page.component.ts" visibleRegion="filter-animations"/>
99+
100+
The code in this example performs the following tasks:
101+
102+
* Skips animations when the user first opens or navigates to this page \(the filter animation narrows what is already there, so it only works on elements that already exist in the DOM\)
103+
* Filters heroes based on the search input's value
104+
105+
For each change:
106+
107+
* Hides an element leaving the DOM by setting its opacity and width to 0
108+
* Animates an element entering the DOM over 300 milliseconds.
109+
During the animation, the element assumes its default width and opacity.
110+
111+
* If there are multiple elements entering or leaving the DOM, staggers each animation starting at the top of the page, with a 50-millisecond delay between each element
112+
113+
## Animating the items of a reordering list
114+
115+
Although Angular animates correctly `*ngFor` list items out of the box, it will not be able to do so if their ordering changes.
116+
This is because it will lose track of which element is which, resulting in broken animations.
117+
The only way to help Angular keep track of such elements is by assigning a `TrackByFunction` to the `NgForOf` directive.
118+
This makes sure that Angular always knows which element is which, thus allowing it to apply the correct animations to the correct elements all the time.
119+
120+
IMPORTANT: If you need to animate the items of an `*ngFor` list and there is a possibility that the order of such items will change during runtime, always use a `TrackByFunction`.
121+
122+
## Animations and Component View Encapsulation
123+
124+
Angular animations are based on the components DOM structure and do not directly take [View Encapsulation](guide/components/styling#style-scoping) into account, this means that components using `ViewEncapsulation.Emulated` behave exactly as if they were using `ViewEncapsulation.None` (`ViewEncapsulation.ShadowDom` behaves differently as we'll discuss shortly).
125+
126+
For example if the `query()` function (which you'll see more of in the rest of the Animations guide) were to be applied at the top of a tree of components using the emulated view encapsulation, such query would be able to identify (and thus animate) DOM elements on any depth of the tree.
127+
128+
On the other hand the `ViewEncapsulation.ShadowDom` changes the component's DOM structure by "hiding" DOM elements inside [`ShadowRoot`](https://developer.mozilla.org/docs/Web/API/ShadowRoot) elements. Such DOM manipulations do prevent some of the animations implementation to work properly since it relies on simple DOM structures and doesn't take `ShadowRoot` elements into account. Therefore it is advised to avoid applying animations to views incorporating components using the ShadowDom view encapsulation.
129+
130+
## Animation sequence summary
131+
132+
Angular functions for animating multiple elements start with `query()` to find inner elements; for example, gathering all images within a `<div>`.
133+
The remaining functions, `stagger()`, [`group()`](api/animations/group), and `sequence()`, apply cascades or let you control how multiple animation steps are applied.
134+
135+
## More on Angular animations
136+
137+
You might also be interested in the following:
138+
139+
<docs-pill-row>
140+
<docs-pill href="guide/legacy-animations" title="Introduction to Angular animations"/>
141+
<docs-pill href="guide/legacy-animations/transition-and-triggers" title="Transition and triggers"/>
142+
<docs-pill href="guide/legacy-animations/reusable-animations" title="Reusable animations"/>
143+
<docs-pill href="guide/routing/route-transition-animations" title="Route transition animations"/>
144+
<docs-pill href="guide/animations/migration" title="Migrating to Native CSS Animations"/>
145+
</docs-pill-row>

0 commit comments

Comments
 (0)