css로 간단한 애니메이션을 만들 때 좋은 animation, @keyframes를 익혀보자!
애니메이션을 재생할 프레임의 스타일을 정의하는 것으로, from(0%)속성에서 to(100%)속성으로 점차 스타일이 변화되며 애니메이션이 재생된다. from / to로 작성하거나, 0% / 50% / 100% 이런 식으로 중간 값을 설정해 작성할 수도 있다.
<style>
@keyframes mybox{
from{ width:100px; } /*너비100부터*/
to{ width:500px; } /*너비 500까지*/
}
.box{
width: 100px;
height: 100px;
background-color:yellow;
animation-name: mybox;
animation-duration: 1s;
animation-direction: alternate; /*반대방향으로*/
animation-iteration-count: infinite; /*무한반복*/
animation-delay: 1s;
animation-timing-function: ease-in-out;
}
</style>
<body>
<p class="box"><p>
</body>
<style>
@keyframes mycircle{
0%{
transform:translate(0,0)
rotate(0);
}
100%{
transform:translate(0,500px) /*위치치정*/
rotate(360deg); /*회전각도*/
width : 120px;
height : 120px;
}
}
.circle{
width: 100px;
height: 100px;
background-color: pink;
border-radius: 50%;
animation: mycircle 1s infinite alternate 0s; /*요약형*/
}
</style>
<body>
<p class="circle"><p>
</body>