Blinking Hello Kitty Angel

HTML

움직이는 귀여운 강아지를 넣어 만든 퀴즈 사이트

xoouxa 2023. 3. 8. 19:14

“ 지연되는 프로젝트에 인력을 더 투입하면 오히려 더 늦어진다. ”

- Frederick Philips Brooks
Mythical Man-Month 저자
728x90

안녕하세요 o((>ω< ))o 오늘은 아직 미완성이지만

 

기본 페이지는 꼬리를 흔드는 강아지,

정답을 맞추면 웃고있는 강아지 ,

맞추지 못하면 울고있는 강아지를 만들어 자바스크립트를 작업해 보도록 하겠습니다.

 

완성작

 

코드

 

HTML 코드입니다.

<!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>퀴즈 이펙트 01</title>

    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/quiz.css">

</head>

<body class="pattern-checks-lg">
    <header id="header">
        <h1><a href="../javascript14.html"></a>Quiz. <em>정답 확인하기 유형</em></h1>
    </header>
    <!--header-->

    <main id="main">
        <div class="quiz__wrap">
            <div class="quiz">
                <div class="quiz__header">
                    <h2 class="quiz__title"> <span></span> <em></em></h2>
                </div>
                <div class="quiz__main">
                    <div class="quiz__question">
                        <em></em>. <span></span>
                    </div>
                    <div class="quiz__view">
                    <div class="dog__wrap">
                        <div class='wrapper'>
                            <div class='card-container'>
                                <div class='dog'>  //like dog, dislike dog으로 설정 가능
                                    <div class='head'>
                                        <div class='ears'></div>
                                        <div class='face'></div>
                                        <div class='eyes'>
                                            <div class='teardrop'></div>
                                        </div>
                                        <div class='nose'></div>
                                        <div class='mouth'>
                                            <div class='tongue'></div>
                                        </div>
                                        <div class='chin'></div>
                                    </div>
                                    <div class='body'>
                                        <div class='tail'></div>
                                        <div class='legs'></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    </div>
                    <div class="quiz__answer">
                        <button class="confirm">정답 확인하기</button>
                        <div class="result">연변대비</div>
                    </div>
                </div>
                <div class="quiz__footer"></div>
            </div>
        </div>

    </main>
    <!--main-->

    <footer id="footer">
        <a href="yuna243441@naver.com">yuna243441@naver.com</a>

 

dog로 설정하는 경우 (기본)

<div class='dog'>

꼬리는 계속 흔들고 있으며, 기본 강아지로 설정됩니다.

 

dog like로 설정하는 경우

<div class='dog like'>

꼬리는 계속 흔들고 있으며, 웃고 있는 강아지로 설정됩니다.

 

 

dog dislike로 설정하는 경우

<div class='dog dislike'>

꼬리는 계속 흔들고 있으며, 울고 있는 강아지로 설정됩니다.

 

 

reset.css코드 입니다.

@import url('https://webfontworld.github.io/DungGeunMo/DungGeunMo.css');
@import url('https://webfontworld.github.io/daegu/DalseoHealing.css');



* {
    margin: 0;
    padding: 0;
}
*, *::before, *::after {
    box-sizing: border-box;
}
a {
    text-decoration: none;
    color: #ffffff;
}
h1,h2,h3,h4,h5,h6{
    font-weight: normal;
}
li,ul,ol {
    list-style: none;
}
img{
    vertical-align: top;
    width: 100%;
}
em {
    font-style: normal;
}
body {
    background:
        radial-gradient(#8cffb8 3px, transparent 4px),
        radial-gradient(#edffc4 3px, transparent 4px),
        linear-gradient(#fff 4px, transparent 0),
        linear-gradient(45deg, transparent 74px, transparent 75px, #edffc4 75px, #edffc4 76px, transparent 77px, transparent 109px),
        linear-gradient(-45deg, transparent 75px, transparent 76px, #edffc4 76px, #edffc4 77px, transparent 78px, transparent 109px),
        #fff;
    background-size: 109px 109px, 109px 109px, 100% 6px, 109px 109px, 109px 109px;
    background-position: 54px 55px, 0px 0px, 0px 0px, 0px 0px, 0px 0px;
}

 

 

 

quiz css 코드입니다.


/* header */
#header {
    position: fixed;
    left: 0;
    top: 0;
    background-color: #ffd9d9;
    color: #fff;
    padding: 10px;
    width: 100%;
    z-index: 1000;
}
#header::before {
    content: '';
    border: 4px ridge pink;
    position: absolute;
    left: 5px;
    top: 5px;
    width: calc(100% - 10px);
    height: calc(100% - 10px);
}
#header h1{
    font-size: 28px;
    padding: 0px 5px 5px 10px;
    font-family: 'DungGeunMo';
    z-index: 10;
    position: relative;
}
#header h1 a {
    color: #fff;
}
#header h1 em{
    font-size: 0.5em;
}





/* footer */
#footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: #ffd9d9;
    text-align: center;
    margin-top: 100px;

}
#footer a{
    color: #fff;
    padding: 20px;
    display: block;
    font-family: 'DungGeunMo';
    z-index: 10;
    position: relative;
}
#footer ::before{
    content: '';
    border: 4px ridge pink;
    position: absolute;
    left: 5px;
    top: 5px;
    width: calc(100% - 16px);
    height: calc(100% - 18px);
}
#main {
    padding: 100px 0;
}
/* quiz__wrap */
.quiz__wrap {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}
.quiz__wrap .quiz{
    max-width: 500px;
    background-color: #f3ffda;
    border: 8px ridge #ff9494;

}
.quiz__header{}
.quiz__title{
    background-color: #ff6d6d;
    border: 3px ridge #ff4646;
    border-bottom-width: 6px;
    padding: 5px;
    font-family: 'DungGeunMo';
    font-size: 16px;
    color: #ffffff;
    text-align: center;
}
.quiz__main{}
.quiz__question {
    padding: 20px;
    font-size: 24px;
    font-family: 'DalseoHealing';
    font-weight: bold;
    line-height: 1.5;
    border-bottom: 6px ridge #71ffa5;
}
.quiz__question em {
    color : #ffd876
}
.quiz__answer {
    font-family: 'DalseoHealing';
    padding: 20px;
    text-align: center;
    font-size: 24px;
    /* border-bottom: 6px ridge #05e658; */
}
.quiz__answer .confirm {
    background-color: #98f1b3;
    border: 3px ridge #dcffa4;
    width: 100%;
    font-family: 'DalseoHealing';
    padding: 10px 20px;
    font-size: 22px;

    cursor: pointer;
    transition: all 0.3s;
    text-shadow: 1px 1px 0px #007d2a;
    font-weight: bold;
}
.quiz__answer .confirm:hover {
    background-color: #7fff7a;
}
.quiz__answer .result {
    background-color: #78ffa0;
    border: 3px ridge #dcffa4;
    width: 100%;
    font-family: 'DalseoHealing';
    padding: 10px 20px;
    font-size: 22px;
    /* display: none; */
}
.quiz__view {
    border-bottom: 6px ridge #fd8383;
}
.quiz__footer{}

/* dog__wrap */
.dog .tail, 
.dog .chin, 
.dog .tongue::before, 
.dog .tongue::after, 
.dog .mouth, 
.dog .nose, 
.dog .teardrop, 
.dog .eyes, 
.dog .face::before, 
.dog .face::after, 
.dog .ears::before, 
.dog .ears::after, 
.dog__wrap {
    transition: 0.2s ease-in;
}
.card-container {
    position: relative;
    width: 360px;
    height: 378px;
    margin: auto;
    padding-top: 125px;
    border-radius: 3%;
    z-index: 0;
}
.card-container::before {
    top: 3%;
    width: 93%;
}
.card-container::after {
    top: 5.5%;
    width: 85%;
}
  
.dog .head,
.dog .body {
    position: relative;
    width: 115px;
}
.dog .head {
    height: 115px;
    border-radius: 50% 50% 0 0;
    margin: 0 auto;
}
.dog .ears {
    position: relative;
    top: -14%;
    width: 100%;
}
.dog .ears::before, .dog .ears::after {
  content: "";
  position: absolute;
  top: 0;
  width: 35px;
  height: 70px;
  background: #CB7A1D;
  border-top: 11px solid #F7AA2B;
  border-left: 7px solid #F7AA2B;
  border-right: 7px solid #F7AA2B;
}
.dog .ears::before {
  left: 0;
  border-radius: 50% 45% 0 0;
}
.dog .ears::after {
  right: 0;
  border-radius: 45% 50% 0 0;
}
.dog .face {
  position: absolute;
  background: #F7AA2B;
  width: 100%;
  height: 100%;
  border-radius: 50% 50% 0 0;
}
.dog .face::before, .dog .face::after {
  content: "";
  display: block;
  margin: auto;
  background: #FEFEFE;
}
.dog .face::before {
  width: 15px;
  height: 35px;
  margin-top: 24px;
  border-radius: 20px 20px 0 0;
}
.dog .face::after {
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  width: 60px;
  height: 65px;
  border-radius: 45% 45% 0 0;
}
.dog .eyes {
  position: relative;
  top: 29%;
  text-align: center;
}
.dog .eyes::before, .dog .eyes::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 100%;
  background: #451d1c;
  margin: 0 14.5%;
}
.dog .teardrop {
  position: absolute;
  top: 125%;
  left: 19%;
  width: 6px;
  height: 6px;
  border-radius: 0 50% 50% 50%;
  transform: rotate(45deg);
  background: #FEFEFE;
  visibility: hidden;
}
.dog .nose {
  position: relative;
  top: 35%;
  width: 16px;
  height: 8px;
  border-radius: 35px 35px 65px 65px;
  background: #451d1c;
  margin: auto;
}
.dog .mouth {
  position: relative;
  top: 34.5%;
  width: 4px;
  height: 6px;
  margin: 0 auto;
  text-align: center;
  background: #451d1c;
}
.dog .mouth::before, .dog .mouth::after {
  content: "";
  position: absolute;
  top: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 4px solid #451d1c;
  border-left-color: transparent;
  border-top-color: transparent;
  z-index: 2;
}
.dog .mouth::before {
  transform: translateX(-89%) rotate(45deg);
}
.dog .mouth::after {
  transform: translateX(-2px) rotate(45deg);
}
.dog .tongue {
  position: relative;
  z-index: 1;
}
.dog .tongue::before, .dog .tongue::after {
  content: "";
  position: absolute;
}
.dog .tongue::before {
  top: 10px;
  left: -7px;
  width: 18px;
  height: 0;
  border-radius: 50%;
  background: #813c3b;
  z-index: -1;
}
.dog .tongue::after {
  top: 14px;
  left: -4px;
  width: 12px;
  height: 0;
  border-radius: 20px;
  background: #F5534F;
  z-index: 5;
}
.dog .chin {
  position: relative;
  top: 47.5%;
  margin: 0 auto;
  width: 12px;
  height: 12px;
  border-top: 10px solid #e8e7ec;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-radius: 2px;
  z-index: 0;
}
.dog .body {
  position: relative;
  height: 139px;
  margin: auto;
  z-index: 0;
}
.dog .body::before, .dog .body::after {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  bottom: 0;
  display: block;
  width: 100%;
  margin: auto;
  background: #F7AA2B;
}
.dog .body::after {
  top: -2px;
  bottom: -1px;
  width: 60px;
  background: #FEFEFE;
}
.dog .tail {
  position: absolute;
  left: -60%;
  bottom: 1px;
  background: #F7AA2B;
  width: 93px;
  height: 15px;
  transform: rotate(45deg);
  transform-origin: 100% 50%;
  border-radius: 25px 0 0 25px;
  z-index: -2;
}
.dog .legs {
  position: absolute;
  bottom: 0;
  left: -10%;
  width: 120%;
  height: 15%;
  background: #F7AA2B;
  border-radius: 10px 10px 0 0;
}
.dog .legs::before, .dog .legs::after {
  content: "";
  position: absolute;
  bottom: 1px;
  background: #CB7A1D;
  z-index: -1;
}
.dog .legs::before {
  left: -7.5%;
  width: 115%;
  height: 55%;
  border-radius: 5px 5px 0 0;
}
.dog .legs::after {
  left: -3.5%;
  width: 107%;
  height: 250%;
  border-radius: 20px 20px 35px 35px;
}
@keyframes movetongue {
  100% {
    height: 27px;
  }
}
@keyframes movetail {
  0% {
    transform: rotate(37deg);
  }
  100% {
    transform: rotate(52deg);
  }
}
@keyframes cry {
  100% {
    visibility: visible;
  }
}

.like {
  background: #ffc1aa;
}

.like .face::before {
  margin-top: 10px;
}

.like .face::after {
  height: 85px;
}

.like .eyes {
  top: 13%;
}

.like .eyes::before,
.like .eyes::after {
  width: 18px;
  height: 5px;
  margin: 0px 12.5%;
  transform: rotate(-37.5deg);
  border-radius: 20px;
}

.like .eyes::after {
  transform: rotate(37.5deg);
}

.like .nose {
  top: 18%;
}

.like .mouth {
  top: 16.5%;
}

.like .tongue::before {
  height: 12px;
}

.like .tongue::after {
  height: 24px;
          animation: movetongue 0.1s linear 0.35s infinite alternate forwards;
}

.like .chin {
  top: 34%;
}

.tail {
          animation: movetail 0.1s linear infinite alternate forwards;
}


.dislike {
  background: #cdcdf6;
}

.dislike .ears::before {
  transform: rotate(-50deg) translate(-7px, 2px);
}

.dislike .ears::after {
  transform: rotate(50deg) translate(7px, 2px);
}

.dislike .face::before {
  margin-top: 28px;
}

.dislike .face::after {
  height: 55px;
}

.dislike .eyes {
  top: 38%;
}

.dislike .eyes::before,
.dislike .eyes::after {
  width: 18px;
  height: 5px;
  margin: 0px 14.5%;
  transform: rotate(-37.5deg);
  border-radius: 20px;
}

.dislike .eyes::after {
  transform: rotate(37.5deg);
}

.dislike .teardrop {
          animation: cry 0.1s ease-in 0.25s forwards;
}

.dislike .nose {
  top: 44%;
}

.dislike .mouth {
  top: 42%;
}

.dislike .chin {
  top: 52%;
}

.dislike .tail {
  transform: rotate(0);
}

 

 

 

바스크립트 코드 입니다.

//선택자
        const quizWrap = document.querySelector(".quiz__wrap");
        const quizTitle = quizWrap.querySelector(".quiz__title span");
        const quizTime = quizWrap.querySelector(".quiz__title em");
        const quizQuestion = quizWrap.querySelector(".quiz__question span"); 
        const quizQuestionNum = quizWrap.querySelector(".quiz__question em"); 
        const quizAnswerConfirm = quizWrap.querySelector(".quiz__answer .confirm"); 
        const quizAnswerResult = quizWrap.querySelector(".quiz__answer .result"); 


        // 문제 정보
        const infoType = "웹디자인 기능사";
        const infoTime = "2012년 1회";
        const infoNumber = "1";
        const infoQuestion = "인접하는 두 색의 경계 부분에 색상, 명도, 채도의 대비가 더욱 강하게 일어나는 현상을 무엇이라 하는가?";
        const infoAnswer ="연변대비";


        //문제 출력
        quizTitle.innerText = infoType;
        quizTime.innerText = infoTime;
        quizQuestionNum.innerText = infoNumber;
        quizQuestion.innerText = infoQuestion;
        quizAnswerResult.innerText = infoAnswer

        //정답 숨기기
        quizAnswerResult.style.display = "none";

        //정답 확인하기

        quizAnswerConfirm.addEventListener("click", function(){
            quizAnswerResult.style.display = "block";
            quizAnswerConfirm.style.display = "none";
        })

    </script>
</body>

</html>

 

 

how to write javascript code ?

 

선택자 안에 변수를 지정해 돔(dom)에서 정보를 가져옵니다.

 

- dom : html, xml등과 같은 문서의 구조를 나타내는 객체모델입니다.

  dom은 문서의 모든 요소를 포함하는 트리 구조를 형성합니다.

 

문제 출력에 innerText 메서드를 통해 값을 넣어줍니다.

 

- innerText는 dom 객체의 속성 중 하나로, 해당 요소의 텍스트 내용을 가져오거나 설정할

  수 있는 속성입니다. innerText는 html요소에서 모든 태그를 제거하고, 텍스트만 가져오는 속성입니다.

  

quizAnswerResult.style.display = "block" 

- result 클래스에 display = "block" 로 추가해주는 코드 입니다.

 

 

quizAnswerConfrim.style.display = "none"

- confrim 클래스에 display = "none"로 추가 해주는 코드 입니다.

 

 

✨ 아직 미완성이지만, 좀 더 다듬고 수정해

완성본으로 가지고 오겠습니다.

오늘도 감사합니다.