docs: improve accessibility of animations example (#41385)
PR Close #41385
This commit is contained in:
parent
386550cdf3
commit
f33fa04fb8
@ -77,7 +77,7 @@ describe('Animation Tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Status Slider Component', () => {
|
describe('Status Slider Component', () => {
|
||||||
const activeColor = 'rgba(255, 165, 0, 1)';
|
const activeColor = 'rgba(117, 70, 0, 1)';
|
||||||
const inactiveColor = 'rgba(0, 0, 255, 1)';
|
const inactiveColor = 'rgba(0, 0, 255, 1)';
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
:host {
|
nav a {
|
||||||
display: block;
|
padding: .7rem;
|
||||||
}
|
|
||||||
|
|
||||||
section {
|
|
||||||
margin-top: 100px;
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
<h1>Animations</h1>
|
<h1>Animations</h1>
|
||||||
|
|
||||||
Toggle All Animations <input type="checkbox" [checked]="!animationsDisabled" (click)="toggleAnimations()"/>
|
<input type="checkbox"
|
||||||
|
id="animation-toggle"
|
||||||
|
[checked]="!animationsDisabled"
|
||||||
|
(click)="toggleAnimations()">
|
||||||
|
<label for="animation-toggle">Toggle All Animations</label>
|
||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
<a id="home" routerLink="/home" routerLinkActive="active">Home</a>
|
<a id="home" routerLink="/home" routerLinkActive="active">Home</a>
|
||||||
|
@ -1,51 +1,33 @@
|
|||||||
.heroes {
|
.heroes {
|
||||||
margin: 0 0 2em 0;
|
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
width: 15em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.heroes li {
|
.heroes li {
|
||||||
position: relative;
|
|
||||||
height: 2.3em;
|
|
||||||
overflow:hidden;
|
overflow:hidden;
|
||||||
margin: .5em;
|
margin: .5em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.heroes li > .inner {
|
.heroes li > .inner {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-color: #EEE;
|
background-color: #EEE;
|
||||||
padding: .3em 0;
|
padding: .3rem 0;
|
||||||
height: 1.6em;
|
height: 1.6rem;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
width: 19em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.heroes li:hover > .inner {
|
.heroes li:hover > .inner {
|
||||||
color: #607D8B;
|
color: black;
|
||||||
background-color: #DDD;
|
background-color: #DDD;
|
||||||
transform: translateX(.1em);
|
transform: translateX(.1em);
|
||||||
}
|
}
|
||||||
|
|
||||||
.heroes a {
|
|
||||||
color: #888;
|
|
||||||
text-decoration: none;
|
|
||||||
position: relative;
|
|
||||||
display: block;
|
|
||||||
width: 250px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.heroes a:hover {
|
|
||||||
color:#607D8B;
|
|
||||||
}
|
|
||||||
|
|
||||||
.heroes .badge {
|
.heroes .badge {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 0.8em 0.7em 0 0.7em;
|
padding: 0.8em 0.7em 0 0.7em;
|
||||||
background-color: #607D8B;
|
background-color: #3d5157;
|
||||||
line-height: 1em;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
left: -1px;
|
left: -1px;
|
||||||
top: -4px;
|
top: -4px;
|
||||||
@ -56,38 +38,12 @@
|
|||||||
border-radius: 4px 0 0 4px;
|
border-radius: 4px 0 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
label {
|
||||||
background-color: #eee;
|
display: block;
|
||||||
border: none;
|
padding-bottom: .5rem;
|
||||||
padding: 5px 10px;
|
|
||||||
border-radius: 4px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
button:hover {
|
|
||||||
background-color: #cfd8dc;
|
|
||||||
}
|
|
||||||
|
|
||||||
button.delete {
|
|
||||||
position: relative;
|
|
||||||
left: 24em;
|
|
||||||
top: -32px;
|
|
||||||
background-color: gray !important;
|
|
||||||
color: white;
|
|
||||||
display: inherit;
|
|
||||||
padding: 5px 8px;
|
|
||||||
width: 2em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
margin-bottom: 2px;
|
margin-bottom: 1rem;
|
||||||
width: 11em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.heroes input {
|
|
||||||
position: relative;
|
|
||||||
top: -3px;
|
|
||||||
width: 12em;
|
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,22 @@
|
|||||||
<h2>Filter/Stagger</h2>
|
<h2>Filter/Stagger</h2>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
<input #criteria (input)="updateCriteria(criteria.value)" placeholder="Search Heroes" />
|
<label for="search">Search heroes: </label>
|
||||||
</form>
|
<input type="text"
|
||||||
|
id="search"
|
||||||
|
#criteria (input)="updateCriteria(criteria.value)"
|
||||||
|
placeholder="Search heroes">
|
||||||
|
</form>
|
||||||
|
|
||||||
<!-- #docregion filter-animations -->
|
<!-- #docregion filter-animations -->
|
||||||
<ul class="heroes" [@filterAnimation]="heroTotal">
|
<ul class="heroes" [@filterAnimation]="heroTotal">
|
||||||
<!-- #enddocregion filter-animations -->
|
<!-- #enddocregion filter-animations -->
|
||||||
<li *ngFor="let hero of heroes" class="hero">
|
<li *ngFor="let hero of heroes" class="hero">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<span class="badge">{{ hero.id }}</span>
|
<span class="badge">{{ hero.id }}</span>
|
||||||
<span>{{ hero.name }}</span>
|
<span>{{ hero.name }}</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<!-- #docregion filter-animations -->
|
<!-- #docregion filter-animations -->
|
||||||
</ul>
|
</ul>
|
||||||
<!-- #enddocregion filter-animations -->
|
<!-- #enddocregion filter-animations -->
|
||||||
|
@ -5,7 +5,8 @@ import { Component } from '@angular/core';
|
|||||||
template: `
|
template: `
|
||||||
<section>
|
<section>
|
||||||
<h2>Open Close Component</h2>
|
<h2>Open Close Component</h2>
|
||||||
<input type="checkbox" [checked]="logging" (click)="toggleLogging()"/> Console Log Animation Events
|
<input type="checkbox" id="log-checkbox" [checked]="logging" (click)="toggleLogging()"/>
|
||||||
|
<label for="log-checkbox">Console Log Animation Events</label>
|
||||||
|
|
||||||
<app-open-close [logging]="logging"></app-open-close>
|
<app-open-close [logging]="logging"></app-open-close>
|
||||||
</section>
|
</section>
|
||||||
|
@ -21,8 +21,8 @@ import { trigger, transition, state, animate, style } from '@angular/animations'
|
|||||||
})),
|
})),
|
||||||
state('closed', style({
|
state('closed', style({
|
||||||
width: '100px',
|
width: '100px',
|
||||||
opacity: 0.5,
|
opacity: 0.8,
|
||||||
backgroundColor: 'green'
|
backgroundColor: '#c6ecff'
|
||||||
})),
|
})),
|
||||||
transition('* => *', [
|
transition('* => *', [
|
||||||
animate('1s')
|
animate('1s')
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.open-close-container {
|
.open-close-container {
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
<nav>
|
<button (click)="toggle()">Toggle Open/Close</button>
|
||||||
<button (click)="toggle()">Toggle Open/Close</button>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div [@openClose]="isOpen ? 'open' : 'closed'"
|
<div [@openClose]="isOpen ? 'open' : 'closed'"
|
||||||
(@openClose.start)="onAnimationEvent($event)"
|
(@openClose.start)="onAnimationEvent($event)"
|
||||||
(@openClose.done)="onAnimationEvent($event)"
|
(@openClose.done)="onAnimationEvent($event)"
|
||||||
class="open-close-container">
|
class="open-close-container">
|
||||||
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p>
|
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,8 +20,8 @@ import { trigger, transition, state, animate, style, AnimationEvent } from '@ang
|
|||||||
// #docregion state2
|
// #docregion state2
|
||||||
state('closed', style({
|
state('closed', style({
|
||||||
height: '100px',
|
height: '100px',
|
||||||
opacity: 0.5,
|
opacity: 0.8,
|
||||||
backgroundColor: 'green'
|
backgroundColor: '#c6ecff'
|
||||||
})),
|
})),
|
||||||
// #enddocregion state2, trigger-wildcard1
|
// #enddocregion state2, trigger-wildcard1
|
||||||
// #docregion transition1
|
// #docregion transition1
|
||||||
|
@ -8,19 +8,19 @@ import { trigger, transition, state, animate, style, keyframes } from '@angular/
|
|||||||
animations: [
|
animations: [
|
||||||
trigger('slideStatus', [
|
trigger('slideStatus', [
|
||||||
state('inactive', style({ backgroundColor: 'blue' })),
|
state('inactive', style({ backgroundColor: 'blue' })),
|
||||||
state('active', style({ backgroundColor: 'orange' })),
|
state('active', style({ backgroundColor: '#754600' })),
|
||||||
|
|
||||||
// #docregion keyframesWithOffsets
|
// #docregion keyframesWithOffsets
|
||||||
transition('* => active', [
|
transition('* => active', [
|
||||||
animate('2s', keyframes([
|
animate('2s', keyframes([
|
||||||
style({ backgroundColor: 'blue', offset: 0}),
|
style({ backgroundColor: 'blue', offset: 0}),
|
||||||
style({ backgroundColor: 'red', offset: 0.8}),
|
style({ backgroundColor: 'red', offset: 0.8}),
|
||||||
style({ backgroundColor: 'orange', offset: 1.0})
|
style({ backgroundColor: '#754600', offset: 1.0})
|
||||||
])),
|
])),
|
||||||
]),
|
]),
|
||||||
transition('* => inactive', [
|
transition('* => inactive', [
|
||||||
animate('2s', keyframes([
|
animate('2s', keyframes([
|
||||||
style({ backgroundColor: 'orange', offset: 0}),
|
style({ backgroundColor: '#754600', offset: 0}),
|
||||||
style({ backgroundColor: 'red', offset: 0.2}),
|
style({ backgroundColor: 'red', offset: 0.2}),
|
||||||
style({ backgroundColor: 'blue', offset: 1.0})
|
style({ backgroundColor: 'blue', offset: 1.0})
|
||||||
]))
|
]))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Introduction to Angular animations
|
# Introduction to Angular animations
|
||||||
|
|
||||||
Animation provides the illusion of motion: HTML elements change styling over time. Well-designed animations can make your application more fun and easier to use, but they aren't just cosmetic. Animations can improve your app and user experience in a number of ways:
|
Animation provides the illusion of motion: HTML elements change styling over time. Well-designed animations can make your application more fun and easier to use, but they aren't just cosmetic. Animations can improve your application and user experience in a number of ways:
|
||||||
|
|
||||||
* Without animations, web page transitions can seem abrupt and jarring.
|
* Without animations, web page transitions can seem abrupt and jarring.
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ Angular's animation system is built on CSS functionality, which means you can an
|
|||||||
|
|
||||||
This guide covers the basic Angular animation features to get you started on adding Angular animations to your project.
|
This guide covers the basic Angular animation features to get you started on adding Angular animations to your project.
|
||||||
|
|
||||||
The features described in this guide — and the more advanced features described in the related Angular animations guides — are demonstrated in an example app available as a <live-example></live-example>.
|
The features described in this guide — and the more advanced features described in the related Angular animations guides — are demonstrated in an example application available as a <live-example></live-example>.
|
||||||
|
|
||||||
#### Prerequisites
|
#### Prerequisites
|
||||||
|
|
||||||
@ -63,16 +63,12 @@ In the component file, add a metadata property called `animations:` within the `
|
|||||||
<code-example path="animations/src/app/app.component.ts" header="src/app/app.component.ts" region="decorator" language="typescript">
|
<code-example path="animations/src/app/app.component.ts" header="src/app/app.component.ts" region="decorator" language="typescript">
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
## Animating a simple transition
|
## Animating a transition
|
||||||
|
|
||||||
Let's animate a simple transition that changes a single HTML element from one state to another. For example, you can specify that a button displays either **Open** or **Closed** based on the user's last action. When the button is in the `open` state, it's visible and yellow. When it's in the `closed` state, it's transparent and green.
|
Let's animate a transition that changes a single HTML element from one state to another. For example, you can specify that a button displays either **Open** or **Closed** based on the user's last action. When the button is in the `open` state, it's visible and yellow. When it's the `closed` state, it's translucent and blue.
|
||||||
|
|
||||||
In HTML, these attributes are set using ordinary CSS styles such as color and opacity. In Angular, use the `style()` function to specify a set of CSS styles for use with animations. You can collect a set of styles in an animation state, and give the state a name, such as `open` or `closed`.
|
In HTML, these attributes are set using ordinary CSS styles such as color and opacity. In Angular, use the `style()` function to specify a set of CSS styles for use with animations. You can collect a set of styles in an animation state, and give the state a name, such as `open` or `closed`.
|
||||||
|
|
||||||
<div class="lightbox">
|
|
||||||
<img src="generated/images/guide/animations/open-closed.png" alt="open and closed states">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
Let's create a new `open-close` component to animate with simple transitions.
|
Let's create a new `open-close` component to animate with simple transitions.
|
||||||
@ -95,7 +91,7 @@ Let's see how Angular's `state()` function works with the `style()` func
|
|||||||
<code-example path="animations/src/app/open-close.component.ts" header="src/app/open-close.component.ts" region="state1" language="typescript">
|
<code-example path="animations/src/app/open-close.component.ts" header="src/app/open-close.component.ts" region="state1" language="typescript">
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
In the `closed` state, shown below, the button has a height of 100 pixels, an opacity of 0.5, and a background color of green.
|
In the `closed` state, shown below, the button has a height of 100 pixels, an opacity of 0.7, and a background color of blue.
|
||||||
|
|
||||||
<code-example path="animations/src/app/open-close.component.ts" header="src/app/open-close.component.ts" region="state2" language="typescript">
|
<code-example path="animations/src/app/open-close.component.ts" header="src/app/open-close.component.ts" region="state2" language="typescript">
|
||||||
</code-example>
|
</code-example>
|
||||||
@ -117,7 +113,7 @@ The `timings` parameter takes a string defined in three parts.
|
|||||||
|
|
||||||
>`animate ('duration delay easing')`
|
>`animate ('duration delay easing')`
|
||||||
|
|
||||||
The first part, `duration`, is required. The duration can be expressed in milliseconds as a simple number without quotes, or in seconds with quotes and a time specifier. For example, a duration of a tenth of a second can be expressed as follows:
|
The first part, `duration`, is required. The duration can be expressed in milliseconds as a number without quotes, or in seconds with quotes and a time specifier. For example, a duration of a tenth of a second can be expressed as follows:
|
||||||
|
|
||||||
* As a plain number, in milliseconds: `100`
|
* As a plain number, in milliseconds: `100`
|
||||||
|
|
||||||
@ -177,10 +173,6 @@ The `trigger()` function describes the property name to watch for changes. When
|
|||||||
|
|
||||||
In this example, we'll name the trigger `openClose`, and attach it to the `button` element. The trigger describes the open and closed states, and the timings for the two transitions.
|
In this example, we'll name the trigger `openClose`, and attach it to the `button` element. The trigger describes the open and closed states, and the timings for the two transitions.
|
||||||
|
|
||||||
<div class="lightbox">
|
|
||||||
<img src="generated/images/guide/animations/triggering-the-animation.png" alt="triggering the animation">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
**Note:** Within each `trigger()` function call, an element can only be in one state at any given time. However, it's possible for multiple triggers to be active at once.
|
**Note:** Within each `trigger()` function call, an element can only be in one state at any given time. However, it's possible for multiple triggers to be active at once.
|
||||||
@ -239,7 +231,7 @@ region="trigger">
|
|||||||
|
|
||||||
### Summary
|
### Summary
|
||||||
|
|
||||||
You learned to add animation to a simple transition between two states, using `style()` and `state()` along with `animate()` for the timing.
|
You learned to add animation to a transition between two states, using `style()` and `state()` along with `animate()` for the timing.
|
||||||
|
|
||||||
You can learn about more advanced features in Angular animations under the Animation section, beginning with advanced techniques in [transition and triggers](guide/transition-and-triggers).
|
You can learn about more advanced features in Angular animations under the Animation section, beginning with advanced techniques in [transition and triggers](guide/transition-and-triggers).
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
Before Width: | Height: | Size: 29 KiB |
Loading…
x
Reference in New Issue
Block a user