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
+43-43Lines changed: 43 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -342,15 +342,15 @@ Aceste valori sunt rareori folosite, deoarece nu reprezintă o animație reală,
342
342
343
343
## Event: "transitionend"
344
344
345
-
When the CSS animation finishes, the `transitionend` event triggers.
345
+
Când animația CSS se termină, se declanșează evenimentul `transitionend`.
346
346
347
-
It is widely used to do an action after the animation is done. Also we can join animations.
347
+
Acesta este utilizat pe scară largă pentru a efectua o acțiune după terminarea animației. De asemenea putem uni animațiile.
348
348
349
-
For instance, the ship in the example below starts to sail there and back when clicked, each time farther and farther to the right:
349
+
De exemplu, nava din exemplul de mai jos începe să navigheze încolo și înapoi atunci când se face clic, de fiecare dată tot mai departe spre dreapta:
350
350
351
351
[iframe src="boat" height=300 edit link]
352
352
353
-
The animation is initiated by the function `go`that re-runs each time the transition finishes, and flips the direction:
353
+
Animația este inițiată de funcția `go`care se reia de fiecare dată când se termină tranziția, și inversează direcția:
354
354
355
355
```js
356
356
boat.onclick=function() {
@@ -359,11 +359,11 @@ boat.onclick = function() {
359
359
360
360
functiongo() {
361
361
if (times %2) {
362
-
//sail to the right
362
+
//navighează la dreapta
363
363
boat.classList.remove('back');
364
364
boat.style.marginLeft=100* times +200+'px';
365
365
} else {
366
-
//sail to the left
366
+
//navighează la stânga
367
367
boat.classList.add('back');
368
368
boat.style.marginLeft=100* times -200+'px';
369
369
}
@@ -379,40 +379,40 @@ boat.onclick = function() {
379
379
};
380
380
```
381
381
382
-
The event object for`transitionend`has a few specific properties:
382
+
Obiectul de eveniment pentru`transitionend`are câteva proprietăți specifice:
383
383
384
384
`event.propertyName`
385
-
: The property that has finished animating. Can be good if we animate multiple properties simultaneously.
385
+
: Proprietatea a cărei animație s-a încheiat. Poate fi bună dacă animăm mai multe proprietăți simultan.
386
386
387
387
`event.elapsedTime`
388
-
: The time (in seconds) that the animation took, without`transition-delay`.
388
+
: Timpul (în secunde) cât a durat animația, fără`transition-delay`.
389
389
390
390
## Keyframes
391
391
392
-
We can join multiple simple animations together using the`@keyframes` CSS rule.
392
+
Putem uni mai multe animații simple împreună folosind regula CSS`@keyframes`.
393
393
394
-
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.
394
+
Aceasta specifică "numele" animației și regulile - ce, când și unde să se anime. Apoi folosind proprietatea`animation`, putem atașa animația la element și specifica parametri adiționali pentru aceasta.
395
395
396
-
Here's an example with explanations:
396
+
Iată un exemplu cu explicații:
397
397
398
398
```html run height=60 autorun="no-epub" no-beautify
399
399
<divclass="progress"></div>
400
400
401
401
<style>
402
402
*!*
403
-
@keyframesgo-left-right { /*give it a name: "go-left-right" */
404
-
from { left: 0px; } /*animate from left: 0px */
405
-
to { left: calc(100%-50px); } /*animate to left: 100%-50px */
403
+
@keyframesgo-left-right { /*dați-i un nume: "go-left-right" */
404
+
from { left: 0px; } /*animați din stânga: 0px */
405
+
to { left: calc(100%-50px); } /*animați spre stânga: 100%-50px */
406
406
}
407
407
*/!*
408
408
409
409
.progress {
410
410
*!*
411
411
animation: go-left-right 3sinfinitealternate;
412
-
/*apply the animation "go-left-right" to the element
413
-
duration 3 seconds
414
-
number of times: infinite
415
-
alternate direction every time
412
+
/*aplică animația "go-left-right" elementului
413
+
durata 3 secunde
414
+
număr de ori: infinit
415
+
direcție alternativă de fiecare dată
416
416
*/
417
417
*/!*
418
418
@@ -425,45 +425,45 @@ Here's an example with explanations:
425
425
</style>
426
426
```
427
427
428
-
There are many articles about `@keyframes`and a [detailed specification](https://drafts.csswg.org/css-animations/).
428
+
Sunt multe articole despre `@keyframes`și o [specificație detaliată](https://drafts.csswg.org/css-animations/).
429
429
430
-
You probably won't need `@keyframes` often, unless everything is in constant motion on your sites.
430
+
Probabil că nu veți avea nevoie des de `@keyframes`, decât dacă totul este în continuă mișcare pe site-urile dumneavoastră.
431
431
432
-
## Performance
432
+
## Performanță
433
433
434
-
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.
434
+
Majoritatea proprietăților CSS pot fi animate, deoarece majoritatea acestora sunt valori numerice. De exemplu, `width`, `color`, `font-size`sunt toate numere. Atunci când le animați, browserul modifică treptat aceste numere cadru cu cadru, creând un efect lin.
435
435
436
-
However, not all animations will look as smooth as you'd like, because different CSS properties cost differently to change.
436
+
Cu toate acestea, nu toate animațiile vor arăta la fel de lin pe cât ați dori, deoarece diferite proprietăți CSS costă diferit pentru a fi modificate.
437
437
438
-
In more technical details, when there's a style change, the browser goes through 3 steps to render the new look:
438
+
În detalii mai tehnice, atunci când există o schimbare de stil, browserul parcurge 3 etape pentru a randa noul aspect:
439
439
440
-
1.**Layout**: re-compute the geometry and position of each element, then
441
-
2.**Paint**: re-compute how everything should look like at their places, including background, colors,
442
-
3.**Composite**: render the final results into pixels on screen, apply CSS transforms if they exist.
440
+
1.**Layout**: se recalculează geometria și poziția fiecărui element, apoi
441
+
2.**Paint**: se recalculează cum ar trebui să arate fiecare element la locul lui, inclusiv fundalul, culorile,
442
+
3.**Composite**: randează rezultatele finale în pixeli pe ecran, aplică transformările CSS dacă acestea există.
443
443
444
-
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>.
444
+
În timpul unei animații CSS, acest proces se repetă la fiecare cadru. Cu toate acestea, proprietățile CSS care nu afectează niciodată geometria sau poziția, cum ar fi `color`, pot sări peste etapa Layout. Dacă o`color`se schimbă, browserul nu calculează o nouă geometrie, ci trece la Paint -> Composite. Și există puține proprietăți care merg direct la Composite. Puteți găsi o listă mai lungă de proprietăți CSS și ce etape declanșează la<https://csstriggers.com>.
445
445
446
-
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.
446
+
Calculele pot dura ceva timp, mai ales în cazul paginilor cu multe elemente și un layout complex. Iar întârzierile sunt de fapt vizibile pe majoritatea dispozitivelor, ceea ce duce la animații "tremurânde", mai puțin fluide.
447
447
448
-
Animations of properties that skip the Layout step are faster. It's even better if Paint is skipped too.
448
+
Animațiile proprietăților care sar peste etapa Layout sunt mai rapide. Este chiar mai bine dacă este sărit și Paint.
449
449
450
-
The`transform`property is a great choice, because:
451
-
- CSS transforms affect the target element box as a whole (rotate, flip, stretch, shift it).
452
-
- CSS transforms never affect neighbour elements.
450
+
Proprietatea`transform`este o alegere excelentă, deoarece:
451
+
-Transformările CSS afectează caseta elementului țintă ca întreg (o rotește, o întoarce, o întinde, o deplasează).
452
+
-Transformările CSS nu afectează niciodată elementele vecine.
453
453
454
-
...So browsers apply`transform` "on top" of existing Layout and Paint calculations, in the Composite stage.
454
+
...Astfel browserele aplică`transform` "peste" calculele existente de Layout și Paint, în etapa Composite.
455
455
456
-
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.
456
+
Cu alte cuvinte, browserul calculează Layout-ul (dimensiuni, poziții), îl pictează cu culori, fundaluri etc în etapa Paint, iar apoi aplică`transform`la casetele de elemente care au nevoie de ea.
457
457
458
-
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.
458
+
Modificările (animațiile) proprietății `transform`nu declanșează niciodată pașii Layout și Paint. Mai mult decât atât, browserul avantajează acceleratorul grafic (un cip special de pe CPU sau de pe placa grafică) pentru transformările CSS, făcându-le astfel foarte eficiente.
459
459
460
-
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.
460
+
Din fericire, proprietatea`transform`este foarte puternică. Utilizând `transform`pe un element, ați putea să-l rotiți și să-l întoarceți, să-l întindeți și să-l micșorați, să-l deplasați și [multe altele](https://developer.mozilla.org/docs/Web/CSS/transform#syntax). Deci în loc de proprietățile `left/margin-left`putem folosi `transform: translateX(…)`, folosi`transform: scale`pentru a mări dimensiunea elementului, etc.
461
461
462
-
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.
462
+
De asemenea proprietatea `opacity`nu declanșează niciodată Layout (de asemenea sare peste Paint în Mozilla Gecko). O putem folosi pentru efecte de afișare/ascundere sau de fade-in/fade-out.
463
463
464
-
Paring`transform`with`opacity`can usually solve most of our needs, providing fluid, good-looking animations.
464
+
Asocierea`transform`cu`opacity`poate rezolva de obicei majoritatea nevoilor noastre, oferind animații fluide și arătoase.
465
465
466
-
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:
466
+
De exemplu, aici apăsând pe elementul`#boat`adaugă clasa cu `transform: translateX(300)`și`opacity: 0`, făcându-l astfel să se deplaseze `300px`spre dreapta și să dispară:
0 commit comments