본문 바로가기

아래로 스크롤 해주세요!

My Reference Book

-

제가 배웠던것을 한곳에 정리해보았어요!

HTML

HTML 태그 톺아보기

HTML

자세히보기

CSS

CSS 속성 톺아보기

CSS

자세히보기

JAVASCRIPT

JS 실행문 톺아보기

JAVASCRIPT

자세히보기

최신댓글

CSS

꼬리 흔드는 강아지를 만들어보자!

by C0Di 2022. 8. 18.
728x90

꼬리 흔드는 강아지 만들기

강아지를 만들어 보겠습니다!


PUG 코드

pug코드를 통해 html로 힘들게 작성했던 부분을 편하게 작성해봅니다

.dog
    .dog-body
      .dog-tail
        .dog-tail
          .dog-tail
            .dog-tail
              .dog-tail
                .dog-tail
                  .dog-tail
                    .dog-tail
    .dog-torso
    .dog-head
      .dog-ears
        .dog-ear
        .dog-ear
      .dog-eyes
        .dog-eye
        .dog-eye
      .dog-muzzle
        .dog-tongue
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>

SCSS 코드

SCSS를 통해 불편하게 적었던 CSS를 편하게 적고 강아지에게 동적효과를 주기위해 animation 효과를 줍니다!

$dog-width: 100px;
$interval: 200ms;
$color-gray: #eaebec;
$easing: ease-in-out;

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
html, body {
  background: #4E4BDD;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
*, *:before, *:after {
  box-sizing: border-box;
  position: relative;
}

//dog
.dog {
  width: $dog-width;
  height: $dog-width;
  z-index: 1;
  
  &:before {
    content: '';
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(black, 0.03);
    transform: translatey(-30%) scale(1.5);
  }
  
  * {
    position: absolute;
  }
}

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

//dog-body
.dog-body {
  top: -50%;
  box-shadow: inset 0 -15px 0 0 $color-gray;
  animation: dog-body $interval $easing infinite alternate;
  
  &:before {
    content:'';
    position: absolute;
    bottom: 90%;
    right: 50%;
    
    width: 90%;
    height: 90%;
    background: rgba(white, 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 $interval $interval / 6 $easing infinite alternate both;
    
    @keyframes dog-tail-blur {
      0% {transform: rotate(0); opacity: 0;}
      50% {opacity: 1;}
      100% {transform: rotate(90deg); opacity: 0;}
    }
  }
  
  @keyframes dog-body{
    from {transform: translatex(-10%)}
    to {transform: translatex(10%)}
  }
}


//dog-head
.dog-head {
  border-radius: 50px;
  animation: dog-head $interval * 9 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
.dog-torso {
  top: -20%;
  box-shadow: inset 0 -15px 0 0 $color-gray;
  animation: dog-torso $interval $easing infinite alternate-reverse;
  
  @keyframes dog-torso {
    0% {transform: translatex(-5%);}
    100% {transform: translatex(5%);}
  }
}

// dog-eyes
.dog-eyes {
  width: 60%;
  top: 55%;
  left: 20%;
  z-index: 1;
  
  &:before {
    content: '';
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 40px;
    background: gray;
    position: absolute;
    top: -10px;
    left: -10px;
    z-index: 0;
    border: 4px solid white;
    border-left-width: 0;
    border-bottom-width: 0;
    border-top-width: 0;
    transform: rotate(-45deg)
    }
}

  
  .dog-eye {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    border: 4px solid #000;
    background: #fff;
    z-index: 1;
    
    &:first-child {
      left: 0;
    }
    &:last-child {
      right: 0;
    }
    }

.dog-muzzle {
  width: 60%;
  left: 20%;
  height: 50%;
  border-bottom-left-radius:100%;
  border-bottom-right-radius:100%;
  bottom: -15%;
  background: white;
  
  &:before, &:after {
    content: '';
    display: block;
    position: absolute;
  }
  
  &:before {
    width: 6px;
    height: 20px;
    bottom: 0;
    background: $color-gray;
    left: calc(50% - 3px);
  }
  
  &: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
.dog-ears {
  width: 40%;
  top: 25%;
  left: 30%;
}

.dog-ear {
  bottom: -10px;
  height: 50px;
  width: 50px;
  background: $color-gray;
  
  &:first-child {
    right: 100%;
    border-bottom-left-radius: 80%;
    border-top-right-radius: 80%;
    box-shadow: inset -15px 15px 0 1px white;
    transform: rotate(10deg);
  }
  &:last-child {
    left: 100%;
    border-bottom-right-radius: 80%;
    border-top-left-radius: 80%;
    box-shadow: inset 15px 15px 0 0 white;
    transform: rotate(-10deg);
  }
}

.dog-tongue {
  width: 40%;
  height: 100%;
  left: calc(50% - 20px);
  z-index: -1;
  transform-origin: center top;
  
  &:before {
    content: '';
    position: absolute;
    left: 8px;
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 40px;
    background: #fd3163;
    animation: dog-tongue-inner $interval / 2 $easing infinite alternate;
    
    @keyframes dog-tongue-inner {
      from {transform: translatey(5%)}
      to {transform: translatey(22%)}
    }
  }
}

// dog-tail
.dog-tail{
  $tail-width: 22px;
  width: $tail-width;
  height: $tail-width * 1.1;
  background: white;
  bottom: 40%;
  border-radius: $tail-width / 2;
  left: calc(50% - #{$tail-width / 2});
  transform-origin: center bottom;
  
  .dog-tail {
    animation: dog-tail-segment $interval $easing infinite alternate;
    
    @keyframes dog-tail-segment {
      0% {transform: rotate(-15deg)}
      100% {transform: rotate(15deg)}
    }
  }
}

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

결과

728x90
반응형

댓글

#HASH_TAGS

-

1

멈추지 않는 ' j ' 시리-즈 울적하니 꽃을 달아봤습니다 Method 숙제가 다양해서 너무 좋아요 코딩 ImageSlideEffect HTML 오늘 조업 마감했습니다. JQuery 메서드 코드 슬라이드 결과 : 월요일 오징어 1Kg 당 3000원 이건 또 뭐람 화사한가요? 오늘은 내가바로 오징어! 오징어 두마리 포획 완료 다크모드 선택해주세요 테스트테스트 필터선택자 오늘도 웹표준은.. 제이쿼리 오징어 한마리 수확 완료! 테스트 scroll-snap-type 내일은 즐거운 월요일 공부 scroll-snap-align