본문 바로가기
CSS

강아지 애니메이션

by 코터틀 2022. 8. 18.
반응형

강아지 애니메이션

Code pen을 사용하여 html(pug)와 css(SCSS)를 사용하여 강아지 애니메이션을 코딩해보았습니다.
SCSS의 대한 자세한 설명은 SCSS 게시글을 확인하여주세요!


HTML

Pug로 작성 후 변환 된 HTML태그 입니다.

<div class="dog">
    <div class="dog-body">
        <div class="dog-tail">
            <div class="dog-tail">
                <div class="dog-tail">
                    <div class="dog-tail">
                        <div class="dog-tail">
                            <div class="dog-tail">
                                <div class="dog-tail">
                                    <div class="dog-tail"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="dog-torso"></div>
    <div class="dog-head">
        <div class="dog-ears">
            <div class="dog-ear"></div>
            <div class="dog-ear"></div>
        </div>
        <div class="dog-eyes">
            <div class="dog-eye"></div>
            <div class="dog-eye"></div>
        </div>
        <div class="dog-muzzle">
            <div class="dog-tongue"></div>
        </div>
    </div>
</div>

CSS

SCSS로 작성 후 변환 된 CSS 입니다.
SCSS버전 CSS는 code pen을 확인하여주세요.

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

html,
body {
    background: linear-gradient(to right, #00b09b, #96c93d);
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

*,
*:before,
*:after {
    box-sizing: border-box;
    position: relative;
}

.dog {
    width: 100px;
    height: 100px;
    z-index: 1;
}

.dog:before {
    content: "";
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.03);
    transform: translatey(-30%) scale(1.5);
}

.dog * {
    position: absolute;
}

.dog-body,
.dog-head,
.dog-torso {
    border-radius: 40%;
    background: #CD8B45;
    position: absolute;
    width: 100%;
    height: 100%;
}

.dog-body {
    top: -50%;
    box-shadow: inset 0 -15px 0 0 #E6B36D;
    animation: dog-body 200ms ease-in-out infinite alternate;
}

.dog-body:before {
    content: "";
    position: absolute;
    bottom: 90%;
    right: 50%;
    width: 90%;
    height: 90%;
    background: rgba(230, 179, 109, 0.4);
    border-top-left-radius: 100%;
    border-bottom-left-radius: 10%;
    border-top-right-radius: 10%;
    transform-origin: right bottom;
    animation: dog-tail-blur 200ms 33.3333333333ms ease-in-out infinite alternate both;
}

@keyframes dog-tail-blur {
    0% {
        transform: rotate(0);
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: rotate(90deg);
    }
}

@keyframes dog-body {
    from {
        transform: translatex(-10%);
    }

    to {
        transform: translatex(10%);
    }
}

.dog-head {
    animation: dog-head 1800ms cubic-bezier(0.11, 0.79, 0, 0.99) infinite;
}

@keyframes dog-head {
    0% {
        transform: rotate(45deg);
    }

    33% {
        transform: rotate(-45deg);
    }

    66% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(45deg);
    }
}

.dog-torso {
    top: -20%;
    background: #CD904A;
    box-shadow: inset 0 -15px 0 0 #E6B36D;
    animation: dog-torso 200ms ease-in-out infinite alternate-reverse;
}

@keyframes dog-torso {
    0% {
        transform: translatex(-5%);
    }

    100% {
        transform: tranlatex(5%);
    }
}

.dog-eyes {
    width: 60%;
    top: 55%;
    left: 20%;
    z-index: 1;
}

.dog-eyes:before {
    content: "";
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 40px;
    background: #A0522D;
    position: absolute;
    top: -10px;
    left: -10px;
    z-index: 0;
    border: 4px solid #CD8B45;
    border-left-width: 0;
    border-bottom-width: 0;
    border-top-width: 0;
    transform: rotate(-45deg);
}

.dog-eye {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #000;
    z-index: 1;
}

.dog-eye:first-child {
    left: 0;
}

.dog-eye:last-child {
    right: 0;
}

.dog-muzzle {
    width: 60%;
    left: 20%;
    height: 50%;
    border-top-left-radius: 100%;
    border-top-right-radius: 100%;
    border-bottom-left-radius: 100%;
    border-bottom-right-radius: 100%;
    bottom: -15%;
    background: #CD853F;
}

.dog-muzzle:before,
.dog-muzzle:after {
    content: "";
    display: block;
    position: absolute;
}

.dog-muzzle:before {
    width: 6px;
    height: 20px;
    bottom: 0;
    background: #8B4513;
    left: calc(50% - 3px);
}

.dog-muzzle:after {
    background: black;
    width: 20px;
    height: 15px;
    bottom: 12px;
    left: calc(50% - 10px);
    border-bottom-left-radius: 60% 60%;
    border-bottom-right-radius: 60% 60%;
    border-top-left-radius: 50% 40%;
    border-top-right-radius: 50% 40%;
}

.dog-ears {
    width: 40%;
    top: 25%;
    left: 30%;
}

.dog-ear {
    bottom: -10px;
    height: 50px;
    width: 50px;
    background: #E6B36D;
}

.dog-ear:first-child {
    right: 100%;
    border-bottom-left-radius: 60%;
    border-top-right-radius: 60%;
    box-shadow: inset -15px 15px 0 1px #CD904A;
    transform: rotate(10deg);
}

.dog-ear:last-child {
    left: 100%;
    border-bottom-right-radius: 60%;
    border-top-left-radius: 60%;
    box-shadow: inset 15px 15px 0 0 #CD904A;
    transform: rotate(-10deg);
}

.dog-tongue {
    width: 40%;
    height: 100%;
    left: calc(50% - 20px);
    z-index: -1;
    transform-origin: center top;
}

.dog-tongue:before {
    content: "";
    position: absolute;
    left: 8px;
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 40px;
    background: #fd3163;
    animation: dog-tongue-inner 100ms ease-in-out infinite alternate;
}

@keyframes dog-tongue-inner {
    from {
        transform: translatey(5%);
    }

    to {
        transform: translatey(22%);
    }
}

.dog-tail {
    width: 22px;
    height: 24.2px;
    background: #CD904A;
    bottom: 40%;
    left: calc(50% - 11px);
    border-radius: 11px;
    transform-origin: center bottom;
}

.dog-tail .dog-tail {
    animation: dog-tail-segment 200ms ease-in-out infinite alternate;
}

@keyframes dog-tail-segment {
    0% {
        transform: rotate(-10deg);
    }

    100% {
        transform: rotate(10deg);
    }
}

.dog-body>.dog-tail {
    bottom: 90%;
}
반응형

'CSS' 카테고리의 다른 글

이미지 스프라이트 / IR 효과 / 백그라운드 표현  (7) 2022.08.20
SCSS/SASS 정리  (13) 2022.08.18
미디어쿼리  (6) 2022.08.15
기본 문법  (6) 2022.08.15
벡터와 비트맵  (8) 2022.08.09

댓글


광고 준비중입니다.