Skip to content

Commit 00f138c

Browse files
authored
Merge pull request #2140 from peachesontour/patch-14
Typos
2 parents d2ebb42 + ebd774d commit 00f138c

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

7-animation/2-css-animations/article.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# CSS-animations
22

3-
CSS animations allow to do simple animations without JavaScript at all.
3+
CSS animations make it possible to do simple animations without JavaScript at all.
44

5-
JavaScript can be used to control CSS animation and make it even better with a little of code.
5+
JavaScript can be used to control CSS animations and make them even better, with little code.
66

77
## CSS transitions [#css-transition]
88

99
The idea of CSS transitions is simple. We describe a property and how its changes should be animated. When the property changes, the browser paints the animation.
1010

11-
That is: all we need is to change the property. And the fluent transition is made by the browser.
11+
That is, all we need is to change the property, and the fluid transition will be done by the browser.
1212

1313
For instance, the CSS below animates changes of `background-color` for 3 seconds:
1414

@@ -47,7 +47,7 @@ There are 4 properties to describe CSS transitions:
4747
- `transition-timing-function`
4848
- `transition-delay`
4949

50-
We'll cover them in a moment, for now let's note that the common `transition` property allows to declare them together in the order: `property duration timing-function delay`, and also animate multiple properties at once.
50+
We'll cover them in a moment, for now let's note that the common `transition` property allows declaring them together in the order: `property duration timing-function delay`, as well as animating multiple properties at once.
5151

5252
For instance, this button animates both `color` and `font-size`:
5353

@@ -70,25 +70,29 @@ growing.onclick = function() {
7070
</script>
7171
```
7272

73-
Now let's cover animation properties one by one.
73+
Now, let's cover animation properties one by one.
7474

7575
## transition-property
7676

77-
In `transition-property` we write a list of property to animate, for instance: `left`, `margin-left`, `height`, `color`.
77+
In `transition-property`, we write a list of properties to animate, for instance: `left`, `margin-left`, `height`, `color`. Or we could write `all`, which means "animate all properties".
7878

79-
Not all properties can be animated, but [many of them](http://www.w3.org/TR/css3-transitions/#animatable-properties-). The value `all` means "animate all properties".
79+
Do note that, there are properties which can not be animated. However, [most of the generally used properties are animatable](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties).
8080

8181
## transition-duration
8282

8383
In `transition-duration` we can specify how long the animation should take. The time should be in [CSS time format](http://www.w3.org/TR/css3-values/#time): in seconds `s` or milliseconds `ms`.
8484

8585
## transition-delay
8686

87-
In `transition-delay` we can specify the delay *before* the animation. For instance, if `transition-delay: 1s`, then animation starts after 1 second after the change.
87+
In `transition-delay` we can specify the delay *before* the animation. For instance, if `transition-delay` is `1s` and `transition-duration` is `2s`, then the animation starts 1 second after the property change and the total duration will be 2 seconds.
8888

89-
Negative values are also possible. Then the animation starts from the middle. For instance, if `transition-duration` is `2s`, and the delay is `-1s`, then the animation takes 1 second and starts from the half.
89+
Negative values are also possible. Then the animation is shown immediately, but the starting point of the animation will be after given value (time). For example, if `transition-delay` is `-1s` and `transition-duration` is `2s`, then animation starts from the halfway point and total duration will be 1 second. You can think it like this:
9090

91-
Here's the animation shifts numbers from `0` to `9` using CSS `translate` property:
91+
`transition-delay + transition-duration = animation duration`
92+
93+
So, if for instance, `transition-delay` is `-2s` and `transition-duration` is `2s`, then it will be as if there was no transitioning animation for that property and the changes are shown instantly. Therefore, "animation duration" must always be greater than `0s` for any animation to be shown.
94+
95+
Here the animation shifts numbers from `0` to `9` using CSS `translate` property:
9296

9397
[codetabs src="digits"]
9498

@@ -108,13 +112,13 @@ In the example above JavaScript adds the class `.animate` to the element -- and
108112
stripe.classList.add('animate');
109113
```
110114

111-
We can also start it "from the middle", from the exact number, e.g. corresponding to the current second, using the negative `transition-delay`.
115+
We could also start it from somewhere in the middle of the transition, from an exact number, e.g. corresponding to the current second, using a negative `transition-delay`.
112116

113117
Here if you click the digit -- it starts the animation from the current second:
114118

115119
[codetabs src="digits-negative-delay"]
116120

117-
JavaScript does it by an extra line:
121+
JavaScript does it with an extra line:
118122

119123
```js
120124
stripe.onclick = function() {
@@ -129,25 +133,25 @@ stripe.onclick = function() {
129133

130134
## transition-timing-function
131135

132-
Timing function describes how the animation process is distributed along the time. Will it start slowly and then go fast or vise versa.
136+
The timing function describes how the animation process is distributed along its timeline. Will it start slowly and then go fast, or vice versa.
133137

134-
That's the most complicated property from the first sight. But it becomes very simple if we devote a bit time to it.
138+
It appears to be the most complicated property at first. But it becomes very simple if we devote a bit time to it.
135139

136-
That property accepts two kinds of values: a Bezier curve or steps. Let's start from the curve, as it's used more often.
140+
That property accepts two kinds of values: a Bezier curve or steps. Let's start with the curve, as it's used more often.
137141

138142
### Bezier curve
139143

140-
The timing function can be set as a [Bezier curve](/bezier-curve) with 4 control points that satisfies the conditions:
144+
The timing function can be set as a [Bezier curve](/bezier-curve) with 4 control points that satisfy the conditions:
141145

142146
1. First control point: `(0,0)`.
143147
2. Last control point: `(1,1)`.
144-
3. For intermediate points values of `x` must be in the interval `0..1`, `y` can be anything.
148+
3. For intermediate points, the values of `x` must be in the interval `0..1`, `y` can be anything.
145149

146150
The syntax for a Bezier curve in CSS: `cubic-bezier(x2, y2, x3, y3)`. Here we need to specify only 2nd and 3rd control points, because the 1st one is fixed to `(0,0)` and the 4th one is `(1,1)`.
147151

148-
The timing function describes how fast the animation process goes in time.
152+
The timing function describes how fast the animation process goes.
149153

150-
- The `x` axis is the time: `0` -- the starting moment, `1` -- the last moment of `transition-duration`.
154+
- The `x` axis is the time: `0` -- the start, `1` -- the end of `transition-duration`.
151155
- The `y` axis specifies the completion of the process: `0` -- the starting value of the property, `1` -- the final value.
152156

153157
The simplest variant is when the animation goes uniformly, with the same linear speed. That can be specified by the curve `cubic-bezier(0, 0, 1, 1)`.
@@ -197,7 +201,7 @@ CSS:
197201

198202
There are several built-in curves: `linear`, `ease`, `ease-in`, `ease-out` and `ease-in-out`.
199203

200-
The `linear` is a shorthand for `cubic-bezier(0, 0, 1, 1)` -- a straight line, we saw it already.
204+
The `linear` is a shorthand for `cubic-bezier(0, 0, 1, 1)` -- a straight line, which we described above.
201205

202206
Other names are shorthands for the following `cubic-bezier`:
203207

@@ -221,9 +225,9 @@ So we could use `ease-out` for our slowing down train:
221225

222226
But it looks a bit differently.
223227

224-
**A Bezier curve can make the animation "jump out" of its range.**
228+
**A Bezier curve can make the animation exceed its range.**
225229

226-
The control points on the curve can have any `y` coordinates: even negative or huge. Then the Bezier curve would also jump very low or high, making the animation go beyond its normal range.
230+
The control points on the curve can have any `y` coordinates: even negative or huge ones. Then the Bezier curve would also extend very low or high, making the animation go beyond its normal range.
227231

228232
In the example below the animation code is:
229233
```css
@@ -244,21 +248,21 @@ But if you click the train, you'll see that:
244248

245249
[codetabs src="train-over"]
246250

247-
Why it happens -- pretty obvious if we look at the graph of the given Bezier curve:
251+
Why it happens is pretty obvious if we look at the graph of the given Bezier curve:
248252

249253
![](bezier-train-over.svg)
250254

251-
We moved the `y` coordinate of the 2nd point below zero, and for the 3rd point we made put it over `1`, so the curve goes out of the "regular" quadrant. The `y` is out of the "standard" range `0..1`.
255+
We moved the `y` coordinate of the 2nd point below zero, and for the 3rd point we made it over `1`, so the curve goes out of the "regular" quadrant. The `y` is out of the "standard" range `0..1`.
252256

253-
As we know, `y` measures "the completion of the animation process". The value `y = 0` corresponds to the starting property value and `y = 1` -- the ending value. So values `y<0` move the property lower than the starting `left` and `y>1` -- over the final `left`.
257+
As we know, `y` measures "the completion of the animation process". The value `y = 0` corresponds to the starting property value and `y = 1` -- the ending value. So values `y<0` move the property beyond the starting `left` and `y>1` -- past the final `left`.
254258

255259
That's a "soft" variant for sure. If we put `y` values like `-99` and `99` then the train would jump out of the range much more.
256260

257-
But how to make the Bezier curve for a specific task? There are many tools. For instance, we can do it on the site <http://cubic-bezier.com/>.
261+
But how do we make a Bezier curve for a specific task? There are many tools. For instance, we can do it on the site <http://cubic-bezier.com/>.
258262

259263
### Steps
260264

261-
Timing function `steps(number of steps[, start/end])` allows to split animation into steps.
265+
The timing function `steps(number of steps[, start/end])` allows splitting an animation into steps.
262266

263267
Let's see that in an example with digits.
264268

@@ -324,11 +328,11 @@ When the CSS animation finishes the `transitionend` event triggers.
324328

325329
It is widely used to do an action after the animation is done. Also we can join animations.
326330

327-
For instance, the ship in the example below starts to swim there and back on click, each time farther and farther to the right:
331+
For instance, the ship in the example below starts to sail there and back when clicked, each time farther and farther to the right:
328332

329333
[iframe src="boat" height=300 edit link]
330334

331-
The animation is initiated by the function `go` that re-runs each time when the transition finishes and flips the direction:
335+
The animation is initiated by the function `go` that re-runs each time the transition finishes, and flips the direction:
332336

333337
```js
334338
boat.onclick = function() {
@@ -337,11 +341,11 @@ boat.onclick = function() {
337341

338342
function go() {
339343
if (times % 2) {
340-
// swim to the right
344+
// sail to the right
341345
boat.classList.remove('back');
342346
boat.style.marginLeft = 100 * times + 200 + 'px';
343347
} else {
344-
// swim to the left
348+
// sail to the left
345349
boat.classList.add('back');
346350
boat.style.marginLeft = 100 * times - 200 + 'px';
347351
}
@@ -357,7 +361,7 @@ boat.onclick = function() {
357361
};
358362
```
359363

360-
The event object for `transitionend` has few specific properties:
364+
The event object for `transitionend` has a few specific properties:
361365

362366
`event.propertyName`
363367
: The property that has finished animating. Can be good if we animate multiple properties simultaneously.
@@ -369,7 +373,7 @@ The event object for `transitionend` has few specific properties:
369373

370374
We can join multiple simple animations together using the `@keyframes` CSS rule.
371375

372-
It specifies the "name" of the animation and rules: what, when and where to animate. Then using the `animation` property we attach the animation to the element and specify additional parameters for it.
376+
It specifies the "name" of the animation and rules - what, when and where to animate. Then using the `animation` property, we can attach the animation to the element and specify additional parameters for it.
373377

374378
Here's an example with explanations:
375379

@@ -405,11 +409,11 @@ Here's an example with explanations:
405409

406410
There are many articles about `@keyframes` and a [detailed specification](https://drafts.csswg.org/css-animations/).
407411

408-
Probably you won't need `@keyframes` often, unless everything is in the constant move on your sites.
412+
You probably won't need `@keyframes` often, unless everything is in constant motion on your sites.
409413

410414
## Summary
411415

412-
CSS animations allow to smoothly (or not) animate changes of one or multiple CSS properties.
416+
CSS animations allow smoothly (or not) animated changes of one or multiple CSS properties.
413417

414418
They are good for most animation tasks. We're also able to use JavaScript for animations, the next chapter is devoted to that.
415419

@@ -419,9 +423,9 @@ Limitations of CSS animations compared to JavaScript animations:
419423
+ Simple things done simply.
420424
+ Fast and lightweight for CPU.
421425
- JavaScript animations are flexible. They can implement any animation logic, like an "explosion" of an element.
422-
- Not just property changes. We can create new elements in JavaScript for purposes of animation.
426+
- Not just property changes. We can create new elements in JavaScript as part of the animation.
423427
```
424428

425-
The majority of animations can be implemented using CSS as described in this chapter. And `transitionend` event allows to run JavaScript after the animation, so it integrates fine with the code.
429+
The majority of animations can be implemented using CSS as described in this chapter. And the `transitionend` event allows JavaScript to be run after the animation, so it integrates fine with the code.
426430

427431
But in the next chapter we'll do some JavaScript animations to cover more complex cases.

0 commit comments

Comments
 (0)