본문 바로가기
CSS

Bounce 애니메이션

by 코터틀 2022. 9. 2.
반응형

Bounce 애니메이션

Code pen을 사용하여 통통 튀는 원형 애니메이션을 만들었습니다.
늘 사용하던 애니메이션 CSS코드를 사용하였으니, 함께 만들어보세요!
오늘의 선생님 고생하셨슴다..


HTML

1개의 공, 4개의 잔상 표현을 위해 총 5개의 wrapper클래스 영역을 생성합니다.

<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

전체 영역을 box-sizing으로 설정해주고, 그라데이션 배경을 설정합니다.
시작 위치를 position으로 설정하여줍니다. 설정한 위치에 도형을 생성하여주고, transform / translate를 사용하여 움직임을 설정합니다.
animation-delay, opacity를 사용하여 마치 공의 잔상이 남은 것 같은 효과를 유도합니다.

* {
    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;
}

.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' 카테고리의 다른 글

SVG Animation  (12) 2022.09.07
SVG Intro  (9) 2022.09.07
circle 애니메이션  (13) 2022.08.29
Box 애니메이션  (9) 2022.08.29
CSS 요소 숨기기  (13) 2022.08.25

댓글


광고 준비중입니다.