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
{{ message }}
Repository navigation
Commit 5f35c46
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: 7-animation/2-css-animations/article.md
+32-32Lines changed: 32 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -409,39 +409,39 @@ boat.onclick = function() {
409
409
410
410
## Продуктивність
411
411
412
-
Most CSS properties can be animated, because most of them are numeric values. For instance, `width`, `color`, `font-size`are all numbers. When you animate them, the browser gradually changes these numbers frame by frame, creating a smooth effect.
412
+
Більшість властивостей CSS можна анімувати, оскільки більшість із них є числовими значеннями. Наприклад, `width`, `color`, `font-size`є числами. Коли ви анімуєте їх, браузер поступово змінює ці числа кадр за кадром, створюючи плавний ефект.
413
413
414
-
However, not all animations will look as smooth as you'd like, because different CSS properties cost differently to change.
414
+
Однак не всі анімації виглядатимуть так гладко, як хотілося б, оскільки різні властивості змінюються по-різному.
415
415
416
-
In more technical details, when there's a style change, the browser goes through 3 steps to render the new look:
416
+
Якщо говорити більше про технічні деталі, коли відбувається зміна стилю, браузер виконує 3 кроки для відтворення нового вигляду:
417
417
418
-
1.**Layout**: re-compute the geometry and position of each element, then
419
-
2.**Paint**: re-compute how everything should look like at their places, including background, colors,
420
-
3.**Composite**: render the final results into pixels on screen, apply CSS transforms if they exist.
418
+
1.**Макет**: перерахувати геометрію, а потім положення кожного елемента
419
+
2.**Фарбування**: перерахувати, як все має виглядати на своїх місцях, включаючи фон, кольори,
420
+
3.**Композиція**: відтворити кінцеві результати в пікселях на екрані, застосувати CSS-перетворення, якщо вони існують.
421
421
422
-
During a CSS animation, this process repeats every frame. However, CSS properties that never affect geometry or position, such as `color`, may skip the Layout step. If a `color`changes, the browser doesn't calculate any new geometry, it goes to Paint -> Composite. And there are few properties that directly go to Composite. You can find a longer list of CSS properties and which stages they trigger at<https://csstriggers.com>.
422
+
Під час CSS-анімації цей процес повторюється для кожного кадра. Однак властивості CSS, які ніколи не впливають на геометрію або положення, наприклад, `color`, можуть пропускатись кроці макета. Якщо `color`змінюється, браузер не обчислює нову геометрію, він переходить до кроків Фарбування -> Композиція. І є кілька властивостей, які безпосередньо переходять до Композиції. Ви можете знайти довший список властивостей CSS та на яких етапах вони запускаються тут<https://csstriggers.com>.
423
423
424
-
The calculations may take time, especially on pages with many elements and a complex layout. And the delays are actually visible on most devices, leading to "jittery", less fluid animations.
424
+
Обчислення може зайняти багато часу, особливо на сторінках із великою кількістю елементів і складним макетом. І затримки фактично помітні на більшості пристроїв, що призводить до «тривожності», менш плавної анімації.
425
425
426
-
Animations of properties that skip the Layout step are faster. It's even better if Paint is skipped too.
426
+
Анімація властивостей, які пропускають крок макета, швидше. Навіть ліпше, ніж у випадку з пропусканням кроку фарбування.
427
427
428
-
The`transform`property is a great choice, because:
429
-
- CSS transforms affect the target element box as a whole (rotate, flip, stretch, shift it).
-Перетворення CSS впливають на блок цільового елемента в цілому (повертають, перевертають, розтягують, зміщують його).
430
+
- CSS-перетворення ніколи не впливають на сусідні елементи.
431
431
432
-
...So browsers apply`transform` "on top" of existing Layout and Paint calculations, in the Composite stage.
432
+
...Тому браузери застосовують`transform` "попереду" наявних обчислень Макету та Фарбування на етапі Композиції.
433
433
434
-
In other words, the browser calculates the Layout (sizes, positions), paints it with colors, backgrounds, etc at the Paint stage, and then applies`transform`to element boxes that need it.
434
+
Іншими словами, браузер обчислює макет (розміри, положення), розфарбовує його за допомогою colors, background тощо на етапі Фарбування, а потім застосовує`transform`до блоків елементів, які цього потребують.
435
435
436
-
Changes (animations) of the `transform`property never trigger Layout and Paint steps. More than that, the browser leverages the graphics accelerator (a special chip on the CPU or graphics card) for CSS transforms, thus making them very efficient.
436
+
Зміни (анімації) властивості `transform`ніколи не запускають кроки Макет та Фарбування. Більше того, браузер використовує графічний прискорювач (спеціальний чіп на ЦП або відеокарті) для CSS-перетворень, що робить їх дуже ефективними.
437
437
438
-
Luckily, the`transform`property is very powerful. By using `transform`on an element, you could rotate and flip it, stretch and shrink it, move it around, and [much more](https://developer.mozilla.org/docs/Web/CSS/transform#syntax). So instead of`left/margin-left`properties we can use `transform: translateX(…)`, use `transform: scale`for increasing element size, etc.
438
+
На щастя, властивість`transform`дуже потужна. Використовуючи `transform`для елемента, ви можете обертати та повертати його, розтягувати та зменшувати, переміщувати та [багато іншого](https://developer.mozilla.org/docs/Web/CSS/transform#syntax). Тому замість властивостей`left/margin-left`ми можемо використовувати `transform: translateX(…)`, `transform: scale`для збільшення розміру елемента, тощо.
439
439
440
-
The`opacity`property also never triggers Layout (also skips Paint in Mozilla Gecko). We can use it for show/hide or fade-in/fade-out effects.
440
+
Властивість`opacity`ніколи не запускає Макет (в Mozilla Gecko також пропускається Фарбування). Ми можемо використовувати його для ефектів відображення/приховування або посилення/згасання.
441
441
442
-
Paring`transform`with`opacity`can usually solve most of our needs, providing fluid, good-looking animations.
442
+
Поєднання`transform`з`opacity`зазвичай може вирішувати більшість наших потреб, забезпечуючи плавну, гарну анімацію.
443
443
444
-
For example, here clicking on the`#boat`element adds the class with `transform: translateX(300)`and`opacity: 0`, thus making it move `300px`to the right and disappear:
444
+
Наприклад, тут клік на елемент`#boat`додає клас із `transform: translateX(300)`та`opacity: 0`, таким чином змушуючи його рухатись на `300px`праворуч і зникати:
- JavaScript animations are flexible. They can implement any animation logic, like an "explosion" of an element.
503
-
- Not just property changes. We can create new elements in JavaScript as part of the animation.
500
+
+ Прості речі робляться просто.
501
+
+ Швидка та легкиа для процесора.
502
+
- Анімації JavaScript є гнучкими. Вони можуть реалізувати будь-яку логіку анімації, навіть «вибух» елемента.
503
+
- Не тільки властивості змінюються. В JavaScript ми можемо створювати нові елементи як частину анімації.
504
504
```
505
505
506
-
In early examples in this chapter, we animate `font-size`, `left`, `width`, `height`, etc. In real life projects, we should use `transform: scale()`and`transform: translate()`for better performance.
506
+
У перших прикладах цього розділу ми анімували `font-size`, `left`, `width`, `height` тощо. У реальних проектах ми повинні використовувати `transform: scale()`і`transform: translate()`для кращої продуктивності.
507
507
508
-
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.
508
+
Більшість анімацій можна реалізувати за допомогою CSS, як описано в цьому розділі. А подія`transitionend`дозволяє запускати JavaScript після анімації, тому вона добре інтегрується з кодом.
509
509
510
-
But in the next chapter we'll do some JavaScript animations to cover more complex cases.
510
+
Але в наступному розділі ми зробимо кілька анімацій JavaScript, щоб охопити більш складні випадки.
0 commit comments