Анимация элементов в CSS

CSS animation позволяет анимировать переход от одного состояния (набора свойств CSS) к следующему, количество переходов не ограничено. Может быть задано одновременно несколько анимаций.

animation: growElement 5s linear infinite;
	.apple {
		width: 50px; height:  50px; 
		border-radius:50%;
		background-color: green; 
		margin: 80px;
		animation:growElement 5s linear infinite alternate;
	}
	
	@keyframes growElement { 
		0% { /* начало цикла анимации */
		}
		50% { /* середина цикла анимации */ 
		transform: scale(2);
		background-color: yellow; 
		}
		100% { /* конец цикла анимации */
		transform: scale(3);
		background-color: red; 
		}
	}
	

Универсальное свойство animation

animation: moveit 4s steps(3,start) 500ms infinite reverse;

test 1 - несколько анимаций одновременно при hover. from(0%) to(100%)

пример

css

.test1 { width: 50px; height: 50px; border-radius:50%; background-color: green; margin: 50px; } @keyframes animationScale { from { } to { transform: scale(3); } } @keyframes animationColor { from { } 50% { background-color: yellow; } to { background-color: orange; } } .test1:hover { animation:animationScale 5s, animationColor 4s; }

html

<div class = "test1"></div>
test 2 - направление анимации normal, reverse, alternate, alternate-reverse

пример

css

.test2 { display: inline-block; border: 10px solid indigo; box-sizing: border-box; width : 20px; height : 20px; margin: 30px; border-radius: 15%; } .normal:hover { animation:keyBlink 2s infinite normal; } .reverse:hover { animation:keyBlink 2s infinite reverse; } .alternate:hover { animation:keyBlink 2s infinite alternate; } .alternate-reverse:hover { animation:keyBlink 2s infinite alternate-reverse; } @keyframes keyBlink { from { } to { transform: scale(4); border: 1px solid transparent; } }

html

<div class = "test2 normal"></div> <div class = "test2 reverse"></div> <div class = "test2 alternate"></div> <div class = "test2 alternate-reverse"></div>
test 3 - остановка анимации

пример

css

.testbox3 { width : 920px; height : 200px; border: 1px solid black; overflow: hidden; } .testbox3 .ball { display: inline-block; width : 40px; height : 40px; border-radius: 50%; } .testbox3 .red { background-color: rgba(256,0,0,.4); } .testbox3 .green { background-color: rgba(0,256,0,.4);} .testbox3 .blue { background-color: rgba(0,0,256,.4); } .testbox3:hover .ball { animation:fly 3s linear infinite alternate; } .testbox3 .ball:hover { animation:fly 3s linear infinite alternate paused, boom 1s infinite alternate; } @keyframes fly { from { } 25% { transform: translate(200px, 160px); } 50% { transform: translate(400px, 0px); } 75% { transform: translate(600px, 160px); } to { transform: translate(800px, 0px); } } @keyframes boom { from { } to { transform: translate(430px, 80px) scale(20); } }

html

<div class = "testbox3"> <div class = "ball red"></div> <div class = "ball green"></div> <div class = "ball blue"></div> </div>

Примеры

Hover me

Emotional face

Emo face

Eyes in the night

Eyes in the night
cat eyes

Ball gravify

gravify

kangaroo

kangaroo