728x90
통토도동 돌아다니는 공 🏐
codepen을 사용해서 통통 튕기며 돌아다니는 공을 만들어 봅시다.
첫번째 공이 먼저 가고 뒤따라 연속적으로 가는 것처럼 만들어보았습니다만.. 속도를 빠르게 하니 그냥 공이네요^^!
#1. HTML 코드를 확인해보자
<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>
#2. CSS 코드를 확인해보자
* {
box-sizing: border-box;
}
body {
background: linear-gradient(to top, blueviolet 0%, pink 100%);
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
padding: 0;
}
.wrapper {
position: absolute;
animation: x 0.3s 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;
}
@keyframes x {
0% {
transform: translatex(-100px);
}
100% {
transform: translatex(100px);
}
}
background: linear-gradient; 선형 그라데이션 설정
animation: ease-in-out; 전환(trasform)효과가 천천히-보통-천천히 순으로 진행
+ x축으로 애니메이션을 주고 하나씩 딜레이 시간 추가
.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 y {
25% {
transform: translatey(-50px);
}
0%, 50%, 100% {
transform: translatey(0);
}
75% {
transform: translatey(50px);
}
}
+ y축도 마찬가지로 애니메이션을 주고 하나씩 딜레이 시간 추가
'CSS > ANIMATION' 카테고리의 다른 글
ANIMATION | CSS 애니메이션 만들기 (6) | 2022.09.08 |
---|---|
ANIMATION | SVG 애니메이션 소개 (5) | 2022.09.08 |
ANIMATION | CSS 애니메이션 소개 (9) | 2022.09.07 |
CSS | 돌아가는 로딩 표시 만들기 (9) | 2022.08.29 |
CSS | 굴러가는 네모 만들기 (4) | 2022.08.29 |
댓글