CSS 애니메이션 연습하기
오늘은 간단하게 css 애니메이션을 이용해서 공이 움직이며 잔상이 남기는듯한 애니메이션을 만들어보겠습니다.
결과
HTML
HTML에 wrapper라는 태그를 5개 만들고 그안에 div 태그를 만들어줍니다.
<div class="wrapper">
<div></div>
</div>
<div class="wrapper">
<div></div>
</div>
<div class="wrapper">
<div></div>
</div>
<div class="wrapper">
<div></div>
</div>
<div class="wrapper">
<div></div>
</div>
CSS
배경색을 넣은뒤 5개의 원을 각자 위치를 잡아주고 애니메이션효과를 주면서 공이 점점 작아지며 흐릿해지게 만들어 잔상처럼 보여주게 만들어줍니다.
* {
box-sizing:border-box;
}
body {
background: linear-gradient(to top, yellowgreen 0%, pink 100%);
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
padding: 0;
}
.wrapper{
position: absolute;
animation: x 1s ease-in-out alternate infinite 0s both
}
.wrapper:nth-of-type(2){
animation-delay : 0.1s;
}
.wrapper:nth-of-type(3){
animation-delay : 0.2s;
}
.wrapper:nth-of-type(4){
animation-delay : 0.3s;
}
.wrapper:nth-of-type(5){
animation-delay : 0.4s;
}
.wrapper>div{
width: 50px;
height: 50px;
background-color: #fff;
border-radius: 100%;
margin: 40px;
animation: y 1s linear infinite 0s both;
}
.wrapper:nth-of-type(2)>div{
animation-delay : 0.1s;
height: 40px;
width: 40px;
opacity:0.8;
}
.wrapper:nth-of-type(3)>div{
animation-delay : 0.2s;
height: 30px;
width: 30px;
opacity:0.6;
}
.wrapper:nth-of-type(4)>div{
animation-delay : 0.3s;
height: 20px;
width: 20px;
opacity:0.4;
}
.wrapper:nth-of-type(5)>div{
animation-delay : 0.4s;
height: 10px;
width: 10px;
opacity:0.2;
}
@keyframes x {
0% {
transform: translateX(-100px);
}
100% {
transform: translateX(100px);
}
}
@keyframes y {
25% {
transform:translatey(-50px);
}
0%,50%,100% {
transform:translatey(0);
}
75% {
transform:translatey(50px);
}
}
'CSS' 카테고리의 다른 글
CSS(SVG) 애니메이션 - 글씨 효과 (8) | 2022.09.07 |
---|---|
SVG - 알아보기 (10) | 2022.09.07 |
CSS - GSAP 알아보기 (10) | 2022.08.29 |
CSS 애니메이션 연습하기02 (9) | 2022.08.29 |
CSS 애니메이션 연습하기01 (7) | 2022.08.29 |
댓글