Skip to content

Commit 96cdee0

Browse files
committed
main sync
1 parent f9397e3 commit 96cdee0

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

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

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Do note that, there are properties which can not be animated. However, [most of
8080

8181
## transition-duration
8282

83-
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`.
83+
In `transition-duration` we can specify how long the animation should take. The time should be in [CSS time format](https://www.w3.org/TR/css3-values/#time): in seconds `s` or milliseconds `ms`.
8484

8585
## transition-delay
8686

@@ -210,7 +210,6 @@ Other names are shorthands for the following `cubic-bezier`:
210210

211211
So we could use `ease-out` for our slowing down train:
212212

213-
214213
```css
215214
.train {
216215
left: 0;
@@ -226,6 +225,7 @@ But it looks a bit differently.
226225
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.
227226

228227
In the example below the animation code is:
228+
229229
```css
230230
.train {
231231
left: 100px;
@@ -254,7 +254,15 @@ As we know, `y` measures "the completion of the animation process". The value `y
254254

255255
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.
256256

257-
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/>.
257+
But how do we make a Bezier curve for a specific task? There are many tools.
258+
259+
- For instance, we can do it on the site <https://cubic-bezier.com>.
260+
- Browser developer tools also have special support for Bezier curves in CSS:
261+
1. Open the developer tools with `key:F12` (Mac: `key:Cmd+Opt+I`).
262+
2. Select the `Elements` tab, then pay attention to the `Styles` sub-panel at the right side.
263+
3. CSS properties with a word `cubic-bezier` will have an icon before this word.
264+
4. Click this icon to edit the curve.
265+
258266

259267
### Steps
260268

@@ -266,7 +274,19 @@ Here's a list of digits, without any animations, just as a source:
266274

267275
[codetabs src="step-list"]
268276

269-
We'll make the digits appear in a discrete way by making the part of the list outside of the red "window" invisible and shifting the list to the left with each step.
277+
In the HTML, a stripe of digits is enclosed into a fixed-length `<div id="digits">`:
278+
279+
```html
280+
<div id="digit">
281+
<div id="stripe">0123456789</div>
282+
</div>
283+
```
284+
285+
The `#digit` div has a fixed width and a border, so it looks like a red window.
286+
287+
We'll make a timer: the digits will appear one by one, in a discrete way.
288+
289+
To achieve that, we'll hide the `#stripe` outside of `#digit` using `overflow: hidden`, and then shift the `#stripe` to the left step-by-step.
270290

271291
There will be 9 steps, a step-move for each digit:
272292

@@ -277,26 +297,28 @@ There will be 9 steps, a step-move for each digit:
277297
}
278298
```
279299

280-
In action:
281-
282-
[codetabs src="step"]
283-
284300
The first argument of `steps(9, start)` is the number of steps. The transform will be split into 9 parts (10% each). The time interval is automatically divided into 9 parts as well, so `transition: 9s` gives us 9 seconds for the whole animation – 1 second per digit.
285301

286302
The second argument is one of two words: `start` or `end`.
287303

288304
The `start` means that in the beginning of animation we need to make the first step immediately.
289305

290-
We can observe that during the animation: when we click on the digit it changes to `1` (the first step) immediately, and then changes in the beginning of the next second.
306+
In action:
307+
308+
[codetabs src="step"]
309+
310+
A click on the digit changes it to `1` (the first step) immediately, and then changes in the beginning of the next second.
291311

292312
The process is progressing like this:
293313

294314
- `0s` -- `-10%` (first change in the beginning of the 1st second, immediately)
295315
- `1s` -- `-20%`
296316
- ...
297-
- `8s` -- `-80%`
317+
- `8s` -- `-90%`
298318
- (the last second shows the final value).
299319

320+
Here, the first change was immediate because of `start` in the `steps`.
321+
300322
The alternative value `end` would mean that the change should be applied not in the beginning, but at the end of each second.
301323

302324
So the process for `steps(9, end)` would go like this:
@@ -307,20 +329,20 @@ So the process for `steps(9, end)` would go like this:
307329
- ...
308330
- `9s` -- `-90%`
309331

310-
Here's `steps(9, end)` in action (note the pause between the first digit change):
332+
Here's `steps(9, end)` in action (note the pause before the first digit change):
311333

312334
[codetabs src="step-end"]
313335

314-
There are also shorthand values:
336+
There are also some pre-defined shorthands for `steps(...)`:
315337

316338
- `step-start` -- is the same as `steps(1, start)`. That is, the animation starts immediately and takes 1 step. So it starts and finishes immediately, as if there were no animation.
317339
- `step-end` -- the same as `steps(1, end)`: make the animation in a single step at the end of `transition-duration`.
318340

319-
These values are rarely used, because that's not really animation, but rather a single-step change.
341+
These values are rarely used, as they represent not a real animation, but rather a single-step change. We mention them here for completeness.
320342

321-
## Event transitionend
343+
## Event: "transitionend"
322344

323-
When the CSS animation finishes the `transitionend` event triggers.
345+
When the CSS animation finishes, the `transitionend` event triggers.
324346

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

0 commit comments

Comments
 (0)