Кувалдин Артем
Разработчик интерфейсов
var foo = null; // object
function doMove() {
foo.style.left = parseInt(foo.style.left) + 1 + 'px';
setTimeout(doMove, 20); // call doMove in 20msec
}
function init() {
foo = document.getElementById('superman'); // get the "foo" object
foo.style.left = '0px'; // set its initial position to 0px
doMove(); // start animating
}
window.onload = init;
На текущий момент нам доступны:
.box {
transform: тип_трансформации(значение);
}
не влияет на окружение
.box {
width: 300px;
height: 100px;
/*transform: translate(X , Y );*/
transform: translate(100px, 100px);
}
.box {
transform: translate(100%, 100%);
}
.box-blue {
transform: translateX(100%);
}
.box-red {
transform: translateY(100%);
}
.blue {
/*Размер элемента = 150%*/
transform: scale(1.5);
}
.red {
/*Размер элемента = 50%*/
transform: scale(0.5);
}
.blue {
/* scale(X, Y )*/
transform: scale(1, 1.5);
}
.green {
/*Размер элемента по оси X = 50%*/
transform: scaleX(0.5);
}
.red {
/*Размер элемента по оси Y = 50%*/
transform: scaleY(0.5);
}
.blue {
transform: scale(1, -1);
}
.green {
transform: scale(-1, 1);
}
.red {
transform: scale(-2);
}
.like {
/*Поворот элемента вокруг оси на 180°*/
transform: rotate(180deg);
}
.like {
transform: rotate(-180deg);
}
.like {
/*Полтора оборота по часовой стрелке*/
transform: rotate(1.5turn);
/*1.5turn = 540deg = 600grad ≈ 9,42478rad*/
}
.red {
transform: skew(45deg, 0); /*skewX(45deg)*/
}
.green {
transform: skew(0, 45deg); /*skewY(45deg)*/
}
.blue {
transform: skew(25deg, 25deg);
}
.box {
transform: scale(2) translateX(100px) rotate(45deg);
}
.box {
transform: rotate(45deg) translateX(100px) scale(2);
}
.box {
transform: rotate(45deg);
transform-origin: left top;
/*transform-origin: 0;*/
/*transform-origin: 0 0;*/
/*transform-origin: 0% 0%;*/
}
создает иллюзию глубины и позволяет перемещать в двумерном пространстве экрана точку вдоль и вокруг оси Z (как бы вглубь экрана и из него).
.3d_perspective {
perspective: 200px;
}
perspective
.3d_perspective {
/* по-умолчанию: perspective-origin: 50% 50%; */
}
.3d_perspective_lt {
perspective-origin: 0 0;
}
.3d_perspective_ct {
perspective-origin: 50% 0%;
}
.3d_perspective_rt {
perspective-origin: right top;
}
perspective-origin
Сообщает о том что дочерние элементы позиционируются в 3D-пространстве.
.wrapper {
/*по умолчанию flat*/
transform-style: preserve-3d;
}
ПримерОпределяет видимость задней стороны объекта.
2D | 3D |
---|---|
translate(x,y) | translate3d(x,y,z) |
scale(x,y) | scale3d(x,y,z) |
rotate(angle) | rotate3d(x,y,z,angle) |
matrix(a, b, c, d, e, f) | matrix3d(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) |
.matrix {
/* matrix(a, c, b, d, tx, ty);*/
transform: matrix(2, 0, 0, 1, 0, 0);;
}
.matrix {
/* matrix(a, c, b, d, tx, ty);*/
transform: matrix(2, 0, 0, 1, 0, 0);
}
Коэффициент | Преобразование | Аналог |
---|---|---|
a | Изменение размера по горизонтали | scaleX() |
b | Наклон по горизонтали | skewX() |
c | Наклон по вертикали | skewY() |
d | Изменение размера по вертикали | scaleY() |
tx | Смещение по горизонтали в пикселах | translateX() |
ty | Смещение по вертикали в пикселах | translateY() |
Коэффициент | Преобразование | Аналог |
---|---|---|
a | Изменение размера по горизонтали | scaleX() |
b | Наклон по горизонтали | skewX() |
c | Наклон по вертикали | skewY() |
d | Изменение размера по вертикали | scaleY() |
tx | Смещение по горизонтали в пикселах | translateX() |
ty | Смещение по вертикали в пикселах | translateY() |
Переходы – это анимация от одного набора CSS свойств к другому. Для перехода необходимо:
.button {
/*Свойство перехода*/
transition-property: transform;
/*Длительность перехода*/
transition-duration: .3s;
}
.button:hover {
transform: scale(1.2);
}
.button {
transition-property: transform, background-color;
transition-duration: 0.3s, 300ms;
/* .3s, .3s ; */
background-color: #ccc;
}
.button:hover {
transform: scale(1.2);
background-color: #f00;
}
.button {
transition-property: transform, background-color;
transition-duration: 0.3s, 500ms;
transition-delay: 0s, 0.5s;
background-color: #ccc;
}
.button:hover {
transform: scale(1.2);
background-color: #f00;
}
.button {
transition-property: transform;
/*функция положения объекта от времени.*/
transition-timing-function: linear;
transition-duration: 0.3s;
}
.button:hover {
transform: translateX(800px);
background-color: #f00;
}
P = (1−t)2P1 + 2(1−t)tP2 + t2P3
.rocket {
transition-property: transform;
/* (x1, y1, x2, y2);*/
transition-timing-function: cubic-bezier(.98, 0, 1, .28);
transition-duration: 3s;
}
.long {
transition-property: transform;
transition-duration: .5s;
transition-delay: 1s;
transition-timing-function: ease-in;
}
.short {
/* property duration [timing-function] [delay]*/
transition: transform 1s ease-in .5s;
}
.multi-short {
transition: transform .5s ease-in,
background-color .5s ease-in 1s;
}
.super-short {
transition: all .5s;
}
Позволяет анимировать переходы между ключевыми кадрами.
Для создания анимации необходимо:
@keyframes animationName {
from {
/*css свойства для первого кадра*/
}
to {
/*css свойства для второго кадра*/
}
}
.box.visible {
animation-name: show;
animation-duration: 2s;
}
@keyframes show {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.box {
opacity: 0;
}
.box.visible {
animation-name: show;
animation-duration: 2s;
}
@keyframes show {
to {
opacity: 1
}
}
.box1:hover { animation-name: blink;
animation-duration: 1s;
}
.box2:hover { animation-name: blink;
animation-duration: 5s;
}
@keyframes blink {
from {
background-color: blue;
}
to {
background-color: green;
}
}
.box:hover { animation-name: blink;
animation-duration: 2s;
}
@keyframes blink {
from {
background-color: blue;
}
50% {
background-color: red;
}
to {
background-color: green;
}
}
.box:hover { animation-name: blink;
animation-duration: 3s;
}
@keyframes blink {
0% { background-color: blue; }
25% { background-color: green; }
50% { background-color: red; }
75% { background-color: yellow; }
100% { background-color: grey; }
}
.box:hover { animation-name: blink;
animation-duration: 10s;
}
@keyframes blink {
0%, 50% {
background-color: blue;
}
25%, 75% {
background-color: green;
}
100% {
background-color: grey;
}
}
.box:hover { animation-name: blink;
animation-duration: 4s;
}
@keyframes blink {
0% {
background-color: blue;
}
25%, 75% {
background-color: green;
}
100% {
background-color: grey;
}
}
.box.visible { animation-name: show;
animation-duration: 2s;
}
@keyframes show {
0% {
opacity: 0;
background-color: blue;
}
50% { background-color: green; }
100% {
opacity: 1;
background-color: red;
}
}
.box.move {
animation-name: move;
animation-duration: 2s;
animation-delay: 1s;
}
@keyframes move {
25%, 75% {
transform: translateX(100%);
}
100% {
transform: translateX(200%);
}
}
.box.move {
animation-name: move;
animation-duration: 8s;
animation-timing-function: cubic-bezier(...);
}
@keyframes move {
0% { transform: translate(0, 0); }
25% {
transform: translate(100%, 0);
animation-timing-function: linear;
}
50% { transform: translate(100%, 200%); }
75% {
transform: translate(0, 200%);
animation-timing-function: linear;
}
100% { transform: translate(0, 0); }
}
.circle:hover {
animation-name: zoom;
animation-duration: 1s;
animation-iteration-count: 3;
}
@keyframes zoom {
0% {
transform: scale(1);
}
100% {
transform: scale(2);
}
}
.seconds {
animation-name: seconds;
animation-duration: 60s;
animation-iteration-count: infinite;
}
Clock
.circle {
animation-name: seconds;
animation-duration: 1s;
animation-iteration-count: 3;
animation-direction: alternate;
}
.circle {
animation-name: seconds;
animation-duration: 1s;
animation-iteration-count: 3;
animation-direction: alternate;
animation-fill-mode: forwards;
}
.long {
animation-name: scale;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-iteration-count: 3;
animation-direction: alternate;
animation-delay: 5s;
animation-fill-mode: forwards;
}
.short {
animation: scale 2s ease-in-out 3 alternate 5s forwards;
}
.multi-short {
animation: scale 2s ease-in, move 2s ease-out;
}
.b-heart {
...
animation: heartBeat 1s ease infinite;
}
.b-heart:hover {
animation-play-state: paused;
}
typing {
width: 0;
white-space: nowrap;
overflow: hidden;
border-right: .05em solid !important;
}
.typing.visible {
animation: typing 4s steps(15) forwards,
caret 1s steps(1) infinite;
}
@keyframes typing { to { width: 15ch; } }
@keyframes caret { 50% { border-color: transparent; } }

.circle.run { animation: spin 4s linear infinite; }
@keyframes spin { to { translate: rotate(1turn); } }

.circle.run img {
animation: spin 4s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0turn)
translateY(-150px)
rotate(1turn);
}
100% {
transform: rotate(1turn)
translateY(-150px)
rotate(0turn);
}
}
.box:hover {
animation: break-style 1s infinite;
}