가오리의 코딩일기

고스트 본문

HTML+CSS+JavaScript/만들기

고스트

류경혜 2022. 5. 14. 21:00

https://www.youtube.com/playlist?list=PL-eeIUD86IjSyxTbGT7wY3Hie_HA5bKvg 

 

HTML+CSS+JS 미니 프로젝트 실습 - 프론트엔드 개발자 입문편

 

www.youtube.com

<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Ghost</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="ghost">
      <div class="body">
        <div class="face">
          <div class="eye"></div>
          <div class="eye"></div>
          <div class="mouse"></div>
        </div>
      </div>
      <div class="bottom">
        <dib class="leg"></dib>
        <dib class="leg"></dib>
        <dib class="leg"></dib>
        <dib class="leg"></dib>
        <dib class="leg"></dib>
      </div>
    </div>
    <script>
      document.body.addEventListener("mousemove", function (e) {
        document.querySelector(".ghost").style.left = e.pageX + "px";
        document.querySelector(".ghost").style.top = e.pageY + "px";
      });
    </script>
  </body>
</html>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  width: 100%;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: black;
}
.ghost {
  animation: moveUpDown 3s infinite;
  position: absolute;
}
@keyframes moveUpDown {
  0% {
    margin-top: 0px;
  }
  50% {
    margin-top: -50px;
  }
  100% {
    margin-top: 0px;
  }
}
.ghost .body {
  width: 120px;
  height: 160px;
  background-color: white;
  border-top-left-radius: 45%;
  border-top-right-radius: 45%;
  position: relative;
}
.ghost .body .face {
  display: flex;
  width: 70px;
  justify-content: space-between;
  flex-wrap: wrap;
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
}
.ghost .body .eye {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background-color: #333;
}
.ghost .body .mouse {
  width: 33px;
  height: 15px;
  background-color: #333;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  margin-left: 18px;
  margin-top: 13px;
}
.ghost .bottom {
  display: flex;
}
.ghost .bottom .leg {
  background-color: white;
  width: 24px;
  height: 15px;
  border-bottom-left-radius: 30px;
  border-bottom-right-radius: 30px;
}
.ghost .bottom .leg:nth-child(2n) {
  background-color: black;
  position: relative;
  top: -6px;
  border-radius: 50%;
}​