You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 7-animation/2-css-animations/article.md
+37-15Lines changed: 37 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ Do note that, there are properties which can not be animated. However, [most of
80
80
81
81
## transition-duration
82
82
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`.
84
84
85
85
## transition-delay
86
86
@@ -210,7 +210,6 @@ Other names are shorthands for the following `cubic-bezier`:
210
210
211
211
So we could use `ease-out` for our slowing down train:
212
212
213
-
214
213
```css
215
214
.train {
216
215
left: 0;
@@ -226,6 +225,7 @@ But it looks a bit differently.
226
225
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.
227
226
228
227
In the example below the animation code is:
228
+
229
229
```css
230
230
.train {
231
231
left: 100px;
@@ -254,7 +254,15 @@ As we know, `y` measures "the completion of the animation process". The value `y
254
254
255
255
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.
256
256
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
+
258
266
259
267
### Steps
260
268
@@ -266,7 +274,19 @@ Here's a list of digits, without any animations, just as a source:
266
274
267
275
[codetabs src="step-list"]
268
276
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
+
<divid="digit">
281
+
<divid="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.
270
290
271
291
There will be 9 steps, a step-move for each digit:
272
292
@@ -277,26 +297,28 @@ There will be 9 steps, a step-move for each digit:
277
297
}
278
298
```
279
299
280
-
In action:
281
-
282
-
[codetabs src="step"]
283
-
284
300
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.
285
301
286
302
The second argument is one of two words: `start` or `end`.
287
303
288
304
The `start` means that in the beginning of animation we need to make the first step immediately.
289
305
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.
291
311
292
312
The process is progressing like this:
293
313
294
314
-`0s` -- `-10%` (first change in the beginning of the 1st second, immediately)
295
315
-`1s` -- `-20%`
296
316
- ...
297
-
-`8s` -- `-80%`
317
+
-`8s` -- `-90%`
298
318
- (the last second shows the final value).
299
319
320
+
Here, the first change was immediate because of `start` in the `steps`.
321
+
300
322
The alternative value `end` would mean that the change should be applied not in the beginning, but at the end of each second.
301
323
302
324
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:
307
329
- ...
308
330
-`9s` -- `-90%`
309
331
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):
311
333
312
334
[codetabs src="step-end"]
313
335
314
-
There are also shorthand values:
336
+
There are also some pre-defined shorthands for `steps(...)`:
315
337
316
338
-`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.
317
339
-`step-end` -- the same as `steps(1, end)`: make the animation in a single step at the end of `transition-duration`.
318
340
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.
320
342
321
-
## Eventtransitionend
343
+
## Event: "transitionend"
322
344
323
-
When the CSS animation finishes the `transitionend` event triggers.
345
+
When the CSS animation finishes, the `transitionend` event triggers.
324
346
325
347
It is widely used to do an action after the animation is done. Also we can join animations.
0 commit comments