728x90
무한으로 튀어다니는 공을 만들어보자.
무한정으로 튀어오르는 공을 css를 통해 만들어보도록 하겠습니다.
HTML
무한으로 튀어오르는 공의 형태륾 만들어주기 위해 'wrapper'클래스를 가진 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
x축과 y축의 이동을 통해 무한으로 돌아가는 공을 만들어 주기 위해 translatex 와 translatey를 이용한 키프레임을 만들어줍니다!!
*{
box-sizing:border-box;
}
body{
background: linear-gradient(to top, #a18cd1 0%, #fbc2eb 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; //애니메이션 'x'를 무한정 반복
}
.wrapper>div{
width: 50px;
height: 50px;
background-color: #fff;
border-radius: 100%;
margin: 40px;
animation: y 1s linear infinite 0s both; //애니에미션 'y' 를 무한정 반복
}
@keyframes x { //키프레임 'x'는
0%{
transform:translatex(-100px) //처음 x축 -100px에서 시작
}
100%{
transform:translatex(100px) //마지막 x축 100px에서 끝
}
}
@keyframes y { //키프레임 'y'는
25%{transform: translatey(-50px);} //25%에는 y축 -50px에 위치
0%, 50%, 100%{transform: translatey(0);} //0%, 50%, 100%에는 y축 0px에 위치
75%{transform: translatey(50px);} //75%에는 y축 50px에 위치
}
.wrapper:nth-of-type(2){animation-delay: 0.1s;} //.wrapper 클래스의 두번째 애니메이션은 0.1초 늦게
.wrapper:nth-of-type(3){animation-delay: 0.2s;} //.wrapper 클래스의 두번째 애니메이션은 0.2초 늦게
.wrapper:nth-of-type(4){animation-delay: 0.3s;} //.wrapper 클래스의 두번째 애니메이션은 0.3초 늦게
.wrapper:nth-of-type(5){animation-delay: 0.4s;} //.wrapper 클래스의 두번째 애니메이션은 0.4초 늦게
.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;}
완성 예제
728x90
반응형
'CSS 애니메이션' 카테고리의 다른 글
점점 Long 해졌다가 Short 해지는 박스 애니메이션 만들기 (11) | 2022.09.22 |
---|---|
CSS로 3D hover 효과를 구현해보자! (5) | 2022.09.20 |
원이 펄럭이는 애니메이션 만들어보기! (3) | 2022.09.19 |
통통 굴러가는 네모박스 📦 (8) | 2022.08.29 |
빙글빙글 돌아가는 원 만들기! (12) | 2022.08.29 |
댓글