๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
EFFECT

[EFFCET] ํŽ˜๋Ÿด๋ ‰์Šค(parallax) ํšจ๊ณผ : ๋ฉ”๋‰ด ์ด๋™

by _ํ† ๋งคํ†  2022. 9. 7.
728x90

๐Ÿ–ฑ ํŽ˜๋Ÿด๋ ‰์Šค ํšจ๊ณผ : ๋ฉ”๋‰ด ์Šคํฌ๋กค๋ง ํšจ๊ณผ ๐Ÿ–ฑ

ํŽ˜๋Ÿด๋ž™์Šค(parallax) ์‹œ์ฐจ๋ž€ ์˜๋ฏธ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์Šคํฌ๋กค๋ง์„ ํ•  ๋•Œ ๋ฐฐ๊ฒฝ๊ณผ ์š”์†Œ๋งˆ๋‹ค ์†๋„ ๋ฐ ํฌ๊ธฐ์˜ ์ฐจ์ด๋ฅผ ์ฃผ์–ด ์ž…์ฒด์ ์œผ๋กœ ๋Š๊ปด์ง€๊ฒŒ ํ•˜๋Š” ํšจ๊ณผ๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค.
์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๋•Œ(active) ํ•ด๋‹น ํ™”๋ฉด์œผ๋กœ ์Šคํฌ๋กค์ด ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์ด๋™ํ•˜๋Š” ํšจ๊ณผ์™€ ์Šคํฌ๋กค์„ ๋‚ด๋ฆด ๋•Œ ํ•ด๋‹น ๋ฒ„ํŠผ์ด ๊ฐ•์กฐ๋˜๋Š” ํšจ๊ณผ๋ฅผ ์‹ค์Šตํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜†



#1. HTML / CSS ์„ค์ •ํ•˜๊ธฐ

! HTML TIP !
๊ฐ ์„น์…˜ ๋ณ„๋กœ ๊ตฌ์กฐ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋•Œ ํฐ ํ‹€๋ถ€ํ„ฐ ๊ตฌ์กฐ๋ฅผ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•œ ํฌ์ธํŠธ ์ž…๋‹ˆ๋‹ค!
๊ตฌ์กฐ๋Š” ๋จผ์ € ํฌ๊ฒŒ nav : ๋ฉ”๋‰ด | main : ๋ฉ”์ธ ์ฝ˜ํ…์ธ (์ด๋ฏธ์ง€, ํ…์ŠคํŠธ) | aside : ์Šคํฌ๋กค์˜ ์œ„์น˜๊ฐ’์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ค๋‹ˆ๋‹ค.
์„ธ๋ถ€์ ์ธ ๊ตฌ์กฐ๋Š” ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค!

โœ๏ธ HTML ์Šคํฌ๋ฆฝํŠธ ๋ณด๊ธฐ
<nav id="parallax__nav">
    <ul>
      <li class="active"><a href="#section1">๋ฉ”๋‰ด1</a></li>
      <li><a href="#section2">๋ฉ”๋‰ด2</a></li>
      <li><a href="#section3">๋ฉ”๋‰ด3</a></li>
      <li><a href="#section4">๋ฉ”๋‰ด4</a></li>
      <li><a href="#section5">๋ฉ”๋‰ด5</a></li>
      <li><a href="#section6">๋ฉ”๋‰ด6</a></li>
      <li><a href="#section7">๋ฉ”๋‰ด7</a></li>
      <li><a href="#section8">๋ฉ”๋‰ด8</a></li>
      <li><a href="#section9">๋ฉ”๋‰ด9</a></li>
    </ul>
  </nav>

  <main id="parallax__cont">
    <div id="contents">
      <section id="section1" class="content__item">
        <span class="content__item__num">01</span>
        <h1 class="content__item__title">section1</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ๋ฏธ๋ž˜๋Š” ํ˜„์žฌ ์šฐ๋ฆฌ๊ฐ€ ๋ฌด์—‡์„ ํ•˜๋Š”๊ฐ€์— ๋‹ฌ๋ ค ์žˆ๋‹ค.
        </p>
      </section>
      <!-- //section1 -->

      <section id="section2" class="content__item">
        <span class="content__item__num">02</span>
        <h1 class="content__item__title">section2</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ์–ด์ œ๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์—†๋‹ค. ์™œ๋ƒํ•˜๋ฉด ๋‚˜๋Š” ์–ด์ œ์™€๋Š” ๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ๋˜์—ˆ๊ธฐ
          ๋•Œ๋ฌธ์ด๋‹ค.
        </p>
      </section>
      <!-- //section2 -->

      <section id="section3" class="content__item">
        <span class="content__item__num">03</span>
        <h1 class="content__item__title">section3</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ์–ธ์ œ๋‚˜ ํ˜„์žฌ์— ์ง‘์ค‘ํ• ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ–‰๋ณตํ• ๊ฒƒ์ด๋‹ค.
        </p>
      </section>
      <!-- //section3 -->

      <section id="section4" class="content__item">
        <span class="content__item__num">04</span>
        <h1 class="content__item__title">section4</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ๋จผ์ € ํ•€ ๊ฝƒ์€ ๋จผ์ €์ง„๋‹ค ๋‚จ๋ณด๋‹ค ๋จผ์ € ๊ณต์„ ์„ธ์šฐ๋ ค๊ณ  ์กฐ๊ธ‰ํžˆ ์„œ๋‘˜๊ฒƒ์ด
          ์•„๋‹ˆ๋‹ค.
        </p>
      </section>
      <!-- //section4 -->

      <section id="section5" class="content__item">
        <span class="content__item__num">05</span>
        <h1 class="content__item__title">section5</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ์ข‹์€ ์„ฑ๊ณผ๋ฅผ ์–ป์œผ๋ ค๋ฉด ํ•œ ๊ฑธ์Œ ํ•œ ๊ฑธ์Œ์ด ํž˜์ฐจ๊ณ  ์ถฉ์‹คํ•˜์ง€ ์•Š์œผ๋ฉด ์•ˆ
          ๋œ๋‹ค.
        </p>
      </section>
      <!-- //section5 -->

      <section id="section6" class="content__item">
        <span class="content__item__num">06</span>
        <h1 class="content__item__title">section6</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ์„ฑ๊ณต์˜ ๋น„๊ฒฐ์€ ๋‹จ ํ•œ ๊ฐ€์ง€, ์ž˜ํ•  ์ˆ˜ ์žˆ๋Š” ์ผ์— ๊ด‘์ ์œผ๋กœ ์ง‘์ค‘ํ•˜๋Š”
          ๊ฒƒ์ด๋‹ค.
        </p>
      </section>
      <!-- //section6 -->

      <section id="section7" class="content__item">
        <span class="content__item__num">07</span>
        <h1 class="content__item__title">section7</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ๊ฟˆ์„ ๊ณ„์† ๊ฐ„์งํ•˜๊ณ  ์žˆ์œผ๋ฉด ๋ฐ˜๋“œ์‹œ ์‹คํ˜„ํ•  ๋•Œ๊ฐ€ ์˜จ๋‹ค.
        </p>
      </section>
      <!-- //section7 -->

      <section id="section8" class="content__item">
        <span class="content__item__num">08</span>
        <h1 class="content__item__title">section8</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ํ”ํžˆ ์‚ฌ๋žŒ๋“ค์€ ๊ธฐํšŒ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ์ง€๋งŒ ๊ธฐํšŒ๋Š” ๊ธฐ๋‹ค๋ฆฌ๋Š” ์‚ฌ๋žŒ์—๊ฒŒ ์žกํžˆ์ง€
          ์•Š๋Š” ๋ฒ•์ด๋‹ค.
        </p>
      </section>
      <!-- //section8 -->

      <section id="section9" class="content__item">
        <span class="content__item__num">09</span>
        <h1 class="content__item__title">section9</h1>
        <figure class="content__item__imgWrap">
          <div class="content__item__img"></div>
        </figure>
        <p class="content__item__desc">
          ์ด๋ฏธ๋๋‚˜๋ฒ„๋ฆฐ ์ผ์„ ํ›„ํšŒํ•˜๊ธฐ ๋ณด๋‹ค๋Š” ํ•˜๊ณ  ์‹ถ์—ˆ๋˜ ์ผ๋“ค์„ ํ•˜์ง€๋ชปํ•œ ๊ฒƒ์„
          ํ›„ํšŒํ•˜๋ผ.
        </p>
      </section>
      <!-- //section9 -->
    </div>
  </main>
  <!-- //main -->

  <aside id="parallax__info">
    <div class="scroll">scrollTop : <span>0</span>px</div>
    <div class="info">
      <ul>
        <li>#section1 offset() : <span class="offset1">0</span>px</li>
        <li>#section2 offset() : <span class="offset2">0</span>px</li>
        <li>#section3 offset() : <span class="offset3">0</span>px</li>
        <li>#section4 offset() : <span class="offset4">0</span>px</li>
        <li>#section5 offset() : <span class="offset5">0</span>px</li>
        <li>#section6 offset() : <span class="offset6">0</span>px</li>
        <li>#section7 offset() : <span class="offset7">0</span>px</li>
        <li>#section8 offset() : <span class="offset8">0</span>px</li>
        <li>#section9 offset() : <span class="offset9">0</span>px</li>
      </ul>
    </div>
  </aside>

! CSS TIP !
1. ๋ฐฐ๊ฒฝ, ๋ฉ”๋‰ด, ์ด๋ฏธ์ง€์™€ ํ…์ŠคํŠธ, ์Šคํฌ๋กค ์œ„์น˜๊ฐ’ ๋ฐ•์Šค ๋“ฑ ๊ฐ ์˜์—ญ ๋ณ„๋กœ ์†์„ฑ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค.
์†์„ฑ์„ ์„ค์ •ํ•  ๋•Œ ๊ณตํ†ต ์†์„ฑ์„ ์ฃผ์–ด์•ผ ํ•  ๋• ๊ณตํ†ต ์„ ํƒ์ž๋ฅผ ๋ถ€์—ฌํ•˜์—ฌ ํ•œ ๋ฒˆ์— ์ž‘์—…ํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค! 2.

โœ๏ธ CSS ์Šคํฌ๋ฆฝํŠธ ๋ณด๊ธฐ : ํŽ˜๋Ÿด๋ ‰์Šค ํšจ๊ณผ
/* parallax__nav */
#parallax__nav {
    position: fixed;
    right: 20px;
    top: 20px;
    z-index: 2000;
    background-color: rgba(95, 95, 95, 0.4);
    padding: 20px 30px;
    border-radius: 50px;
}

#parallax__nav li {
    display: inline;
    margin: 0 5px;
}

#parallax__nav li a {
    display: inline-block;
    /* width: 30px; */
    height: 30px;
    padding: 5px 20px;
    text-align: center;
    line-height: 30px;
}

#parallax__nav li.active a {
    background: #fff;
    color: #000;
    border-radius: 20px;
    box-sizing: content-box;
}

#parallax__cont {
    max-width: 1600px;
    /* background-color: rgba(255,255,255,0.1); */
    width: 98%;
    margin: 0 auto;
}

.content__item {
    width: 1000px;
    max-width: 70vw;
    margin: 30vw auto;
    /* background-color: rgba(255,255,255,0.1); */
    text-align: left;
    margin-right: 0;
    position: relative;
    padding-top: 10vw;
}

.content__item:nth-child(even) {
    margin-left: 0;
    text-align: right;
}
.content__item__num {
    font-size: 35vw;
    font-family: "Lato";
    font-weight: 100;
    position: absolute;
    left: -5vw;
    top: -16vw;
    opacity: 0.07;
    z-index: -2;
}
.content__item:nth-child(even) .content__item__num {
    right: -5vw;
    left: auto;
}
.content__item__title {
    font-weight: 400;
    text-transform: capitalize; /* ์ฒซ๊ธ€์ž๋งŒ ๋Œ€๋ฌธ์ž */
}
.content__item__imgWrap {
    width: 100%;
    padding-bottom: 56.25%;
    background: #000;
    position: relative;
    overflow: hidden;
    z-index: -1;
}
.content__item__img {
    position: absolute;
    width: 110%;
    height: 110%;
    left: -5px;
    top: -5px;
    background-image: url(../assets/img/city_bg02.jpg);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    filter: saturate(0%);
    transition: all 1s;
}

.content__item:nth-child(2) .content__item__img {
    background-image: url(../assets/img/city_bg03.jpg);
}
.content__item:nth-child(3) .content__item__img {
    background-image: url(../assets/img/city_bg04.jpg);
}
.content__item:nth-child(4) .content__item__img {
    background-image: url(../assets/img/city_bg05.jpg);
}
.content__item:nth-child(5) .content__item__img {
    background-image: url(../assets/img/Mountian_bg01.jpg);
}
.content__item:nth-child(6) .content__item__img {
    background-image: url(../assets/img/Mountian_bg02.jpg);
}
.content__item:nth-child(7) .content__item__img {
    background-image: url(../assets/img/Mountian_bg03.jpg);
}
.content__item:nth-child(8) .content__item__img {
    background-image: url(../assets/img/Mountian_bg04.jpg);
}
.content__item:nth-child(9) .content__item__img {
    background-image: url(../assets/img/Mountian_bg05.jpg);
}

.content__item__desc {
    font-size: 4vw;
    line-height: 1.4;
    margin-top: -5vw;
    margin-left: -4vw;
    word-break: keep-all;
}

.content__item:nth-child(even) .content__item__desc {
    margin-left: auto;
    margin-right: -4vw;
}

#parallax__info {
    position: fixed;
    left: 20px;
    bottom: 20px;
    z-index: 2000;
    background: rgba(0, 0, 0.4);
    color: #fff;
    padding: 20px;
    border-radius: 10px;
}

#parallax__info li,
.scrollTop {
    line-height: 1.4;
}

@media (max-width: 800px) {
    #parallax__cont {
    margin-top: 70vw;
    }
    #parallax__nav {
    padding: 10px;
    right: auto;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 5px;
    background-color: rgba(0, 0, 0, 0.8);
    }
    #parallax__nav li {
    display: block;
    margin: 5px;
    }
    #parallax__nav li a {
    font-size: 14px;
    padding: 5px;
    border-radius: 5px;
    height: auto;
    line-height: 1;
    }
    #parallax__nav li.active a {
    border-radius: 5px;
    }
    #parallax__info {
    left: 10px;
    bottom: 10px;
    }
}
โœ๏ธ CSS ์Šคํฌ๋ฆฝํŠธ ๋ณด๊ธฐ : ํŽ˜์ด์ง€ ์„น์…˜
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #222;
    color: #fff;
    font-weight: 300;
    font-family: 'Pretendard';
}

img {
    width: 100%;
    vertical-align: top; /* ์ด๋ฏธ์ง€ ์ •๋ ฌ */
}

a {
    color: #fff;
    text-decoration: none;
}

li {
    list-style: none;
}

/* scroll */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #28293600;
}
::-webkit-scrollbar-thumb {
    background: rgba(136, 136, 136, 0.500);
    border-radius: 20px;
}

/* layout */
#header {
    z-index: 2000; /* ์ œํŠธ ์ธ๋ฑ์Šค๋Š” ์„œ๋กœ ํ˜•์ œ์—ฌ์•ผ ํ•˜๋ฉฐ ๊ผญ ํฌ์ง€์…˜์„ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด์ฃผ์–ด์•ผ ํ•œ๋””. */
}
#main {
    width: 100%;
    height: 100vh;
    position: relative;
    z-index: 1000;
}
#footer {
    position: relative;
    z-index: 3000;
}

/* header */
#header {
    position: absolute;
    left: 0;
    top: 0;
    color: #fff;
    padding: 20px;
}
#header h1 {
    display: inline-block;
    font-weight: 200;
    margin-bottom: 10px;
    border-bottom: 0.5px solid #fff;
}
#header p {
    font-weight: 200;
    font-size: 18px;
    margin-bottom: 10px;
}
#header li {
    display: inline-block;
}
#header li a {
    border: 1px solid #fff;
    border-radius: 50%;
    display: inline-block;
    width: 30px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    font-size: 14px;
}
#header li.active a {
    background-color: #fff;
    color: #282936;
}

/* footer */
#footer .source {
    position: absolute;
    right: 20px;
    bottom: 20px;
    border: 1px solid #fff;
    border-radius: 40px;
    padding: 10px 30px;
    font-size: 14px;
}

/* modal__wrap */
.modal__btn {
    color: #fff;
    border: 1px solid #fff;
    border-radius: 50px;
    display: inline-block;
    padding: 10px 20px;
    position: absolute;
    right: 20px;
    bottom: 20px;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
}
.modal__btn:hover {
    background-color: #f5f5f5;
    color: #555;
}

.modal__cont {
    font-size: 14px;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.85);
    position: fixed;
    left: 0;
    top: 0;
    overflow-x: hidden; /* X์ถ•์œผ๋กœ๋Š” ์Šคํฌ๋กค ๋ฐ”๊ฐ€ ์ƒ๊ธฐ์ง€ ์•Š๊ฒŒ ํ•ด์ค€๋‹ค. */
    display: flex;
    align-items: center; /* ๊ฐ€์šด๋ฐ ์ •๋ ฌ aic */
    justify-content: center; /* ๊ฐ€์šด๋ฐ ์ •๋ ฌ jcc */
    transform: scale(0); /* ์š”์†Œ ์•ˆ๋ณด์ด๊ฒŒ ํ•˜๊ธฐ */
}

.modal__box {
    width: 70%;
    height: 70vh;
    border-radius: 0.6rem;
    box-shadow: 0 10px 20px -5px hsl(180deg 2% 10%); /* ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ํŽธํ•œ ์ปฌ๋Ÿฌ ์„ค์ • ๋‹จ์œ„! */
    transform: scale(0);
}
.modal__box .title {
    padding-inline: 1rem;
    background-color: hsl(252 24% 10%);
    display: flex;
    align-items: center;
    color: #fff;
    height: 50px;
    border-top-left-radius: 0.5rem;
    border-top-right-radius: 0.5rem;
}
.modal__box .title .dot {
    width: 15px;
    height: 15px;
    background-color: hsl(180 2% 50%);
    display: inline-block;
    border-radius: 50%;
    position: relative;
    margin-left: 2rem;
}
.modal__box .title .dot::before {
    content: "";
    position: absolute;
    left: 25px;
    top: 0;
    width: 15px;
    height: 15px;
    background-color: hsl(180 2% 50%);
    border-radius: 50%;
}
.modal__box .title .dot::after {
    content: "";
    position: absolute;
    right: 25px;
    top: 0;
    width: 15px;
    height: 15px;
    background-color: hsl(180 2% 50%);
    border-radius: 50%;
}
.modal__box .title .plus {
    background: hsl(242 19% 21%);
    padding: 0.5rem 0.5rem 0.3rem 0.5rem;
    border-radius: 0.5rem;
    color: #7a7d9d;
}
.modal__box .title .tabs {
    display: flex;
    margin-left: 50px;
}
.modal__box .title .tabs > div {
    color: hsl(39 50% 59%);
    background-color: hsl(242 19% 21%);
    padding: 0.35rem 0.8rem 0.25rem 0.8rem;
    margin-right: 0.5rem;
    display: flex;
    align-items: center;
    border-radius: 0.4rem;
    text-transform: uppercase;
    cursor: pointer;
}
.modal__box .title .tabs > div.active {
    background-color: black;
}
.modal__box .title .tabs > div em {
    font-style: normal;
}
.modal__box .title .tabs > div .favicon {
    margin-right: 0.4rem;
    margin-top: 0.2rem;
}
.modal__box .title .tabs > div .close {
    margin-left: 5rem;
}
.modal__box .cont {
    background-color: #282936; /* cont ๋ฐฐ๊ฒฝ์ƒ‰ */
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}
.modal__box .cont > div {
    display: none;
}
.modal__box .cont > div.active {
    display: block;
    height: 100%;
}

.modal__close {
    position: absolute;
    right: 20px;
    top: 20px;
    background-color: #1f224a;
    padding: 1rem 1rem 0.8rem 1rem;
    border-radius: 5px;
    box-shadow: 0 5px 7px -5px hsl(180deg 2% 10%);
    cursor: pointer;
    transition: all 0.3s;
    opacity: 0;
}
.modal__close:hover {
    background-color: #33377d;
}
.modal__close svg {
    color: #fff;
}

/* ๋ชจ๋‹ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜ */
.modal__cont.show {
    /* ์ „์ฒด ๋ฐฐ๊ฒฝ */
    animation: foldOut 1s ease forwards; /* forwards ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์ž‘๋™๋œ ํ›„ ๊ณ ์ •*/
}
.modal__cont.show.hide {
    animation: foldIn 0.3s 0.5s ease backwards;
}
.modal__cont.show .modal__box {
    /* ์ŠคํŠธ๋ฆฝํŠธ ๋ฐฐ๊ฒฝ */
    transform: scale(0);
    animation: zoomOut 0.5s 1s ease forwards;
}
.modal__cont.show.hide .modal__box {
    animation: zoomIn 0.5s ease forwards;
}
.modal__cont.show .modal__close {
    /* ๋‹ซ๊ธฐ ๋ฒ„ํŠผ */
    animation: opacityOut 0.8s 1s ease forwards;
}
.modal__cont.show.hide .modal__close {
    animation: opacityIn 0.3s ease forwards;
}

@keyframes foldOut {
    /* show๊ฐ€ ๋ถ™์—ˆ์„ ๋•Œ ์ž‘๋™๋˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜*/
    0% {
    transform: scaleX(0) scaleY(0.001);
    }
    50% {
    transform: scaleX(1) scaleY(0.001);
    }
    100% {
    transform: scaleX(1) scaleY(1);
    }
}
@keyframes foldIn {
    /* show hide๊ฐ€ ๋ถ™์—ˆ์„ ๋•Œ ์ž‘๋™๋˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜*/
    0% {
    transform: scaleX(1) scaleY(1);
    }
    50% {
    transform: scaleX(1) scaleY(0.001);
    }
    100% {
    transform: scaleX(0) scaleY(0.001);
    }
}
@keyframes zoomOut {
    /* show๊ฐ€ ๋ถ™์—ˆ์„ ๋•Œ ์ž‘๋™๋˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜*/
    0% {
    transform: scale(0);
    }
    100% {
    transform: scale(1);
    }
}
@keyframes zoomIn {
    /* show hide๊ฐ€๊ฐ€ ๋ถ™์—ˆ์„ ๋•Œ ์ž‘๋™๋˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜*/
    0% {
    transform: scale(1);
    }
    100% {
    transform: scale(0);
    }
}
@keyframes opacityOut {
    0% {
    opacity: 0;
    }
    100% {
    opacity: 1;
    }
}
@keyframes opacityIn {
    /* show hide๊ฐ€ ๋ถ™์—ˆ์„ ๋•Œ ์ž‘๋™๋˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜*/
    0% {
    opacity: 1;
    }
    100% {
    opacity: 0;
    }
}

@media (max-width: 1100px) {
    .modal__box .title {
    overflow: hidden;
    }
    .modal__box .title .dot {
    display: none;
    }
    .modal__box .title .tabs {
    margin-left: 0; /* ์ค„์˜€์„ ๋•Œ ์ƒ๋‹จ ์› ์ง€์šฐ๊ธฐ*/
    }
    .modal__box .title .dot > div .close {
    display: none;
    }
}
@media (max-width: 800px) {
    #header {
    width: 100%;
    text-align: center;
    }
    #header h1 {
    line-height: 1.4;
    }
    .modal__box {
    width: 96%;
    }
}    

#2. JAVASCRIPT : ์Šคํฌ๋ฆฝํŠธ๋กœ ํŽ˜๋Ÿด๋ž™์Šค ํšจ๊ณผ ์ฃผ๊ธฐ

๋‹ค์Œ์€ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์Šคํฌ๋ฆฝํŠธ ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค! ๋จผ์ € ์˜ˆ์‹œ ์‚ฌ์ง„์„ ๋ณด๋ฉด์„œ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์–ด๋–ป๊ฒŒ ์ž‘๋™๋˜๋Š”์ง€ ํ™•์ธํ•ด๋ด…์‹œ๋‹ค! ๐Ÿฅน

๐Ÿ’ก ์ „์ฒด ์Šคํฌ๋ฆฝํŠธ ๋ณด๊ธฐ

๋‹ค์Œ์€ ์ „์ฒด์ ์ธ ์Šคํฌ๋ฆฝํŠธ ์ž…๋‹ˆ๋‹ค. ์ฃผ์„์œผ๋กœ ์ฒ˜๋ฆฌ๋œ ๋ถ€๋ถ„์€ ์„ค๋ช… ์™ธ์˜ ๊ฐ๊ฐ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ์ž‘์„ฑ๋œ ์Šคํฌ๋ฆฝํŠธ๋กœ ์ฐธ๊ณ ์ •๋„๋งŒ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค!
์™œ ๋‹ค๋ฅธ ๋ฐฉ์‹์˜ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์•„๋‹Œ ์•„๋ž˜์˜ ์ตœ์ข… ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๋‚˜์™”๋Š”์ง€ ์ •๋„๋กœ๋งŒ ๋ณด์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๐Ÿ˜Š

const scroll = document.querySelector("#parallax__info .scroll span");

    window.addEventListener("scroll", () => {
      // let scrollTop = window.pageYOffset;
      // let scrollTop = window.scrollY;
      // let scrollTop = document.documentElement.scrollTop;
      let scrollTop = window.pageYOffset || window.scrollY || document.documentElement.scrollTop;

      // if(scrollTop >= document.getElementById("section1").offsetTop){
      //   document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(1)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section2").offsetTop){
      //   document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(2)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section3").offsetTop){
      //   document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(3)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section4").offsetTop){
      //   document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(4)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section5").offsetTop){
      //   document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(5)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section6").offsetTop){
      //    document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(6)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section7").offsetTop){
      //    document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(7)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section8").offsetTop){
      //    document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(8)").classList.add("active");
      // }
      // if(scrollTop >= document.getElementById("section9").offsetTop){
      //    document.querySelectorAll("#parallax__nav li").forEach(li => {
      //     li.classList.remove("active");
      //   });
      //   document.querySelector("#parallax__nav li:nth-child(9)").classList.add("active");
      // }

      // for(let i=1; i<=9; i++){
      //   if(scrollTop >= document.getElementById("section"+i).offsetTop){
      //     document.querySelectorAll("#parallax__nav li").forEach(li => {
      //       li.classList.remove("active");
      //     });
      //     document.querySelector("#parallax__nav li:nth-child("+i+")").classList.add("active");
      //   }
      // }

      // forEach
      document.querySelectorAll(".content__item").forEach((el, index) => {
        if (scrollTop >= el.offsetTop - 2) {
          document.querySelectorAll("#parallax__nav li").forEach((li) => {
            li.classList.remove("active");
          });
          document
            .querySelector("#parallax__nav li:nth-child(" + (index + 1) + ")")
            .classList.add("active");
        }
      });

      //info
      // scroll.innerText = Math.round(scrollTop);
      document.querySelector(".scroll span").innerText =
        Math.round(scrollTop);

      // document.querySelector(".offset1").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset2").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset3").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset4").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset5").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset6").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset7").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset8").innerText = document.getElementById("section1").offsetTop;
      // document.querySelector(".offset9").innerText = document.getElementById("section1").offsetTop;

      //for()
      for (let i = 1; i <= 9; i++) {
        document.querySelector(".offset" + i).innerText =
          document.getElementById("section" + i).offsetTop;
      }

      //์Šคํฌ๋กค ์ด๋™
      document.querySelectorAll("#parallax__nav li a").forEach((li) => {
        li.addEventListener("click", (e) => {
          e.preventDefault(); //ํด๋ฆญํ–ˆ์„ ๋•Œ ๋ฉ”๋‰ด์— ๋งํฌ ๋œ ์˜์—ญ์„ ์—†์•ฐ. ์ฆ‰ a ํƒœ๊ทธ๋ฅผ ๋ˆŒ๋ €์„๋•Œ๋„ href ๋งํฌ๋กœ ์ด๋™ํ•˜์ง€ ์•Š๊ฒŒํ•จ
          document.querySelector(li.getAttribute("href")).scrollIntoView({ //ํŠน์ •์œ„์น˜๋กœ ํ™”๋ฉด์„ ์ด๋™์‹œํ‚ค๋Š” ๋ฉ”์„œ๋“œ : scrollIntoView ์ฆ‰ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„๋•Œ ์›ํ•˜๋Š” ๋‚ด์šฉ์ด ์žˆ๋Š” ์œ„์น˜๋กœ ์ด๋™์‹œ์ผœ์•ผ ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
            behavior: "smooth", //๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์›€์ง์ด๋„๋ก : ์Šคํฌ๋กค์ด ์›€์ง์ผ ๋•Œ.
          });
        });
      });
    });

โ—๏ธ ๊ทธ๋Ÿผ ๋‹ค์Œ์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉฐ ์ฃผ์„๊ณผ ํ•จ๊ป˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์•Œ์•„๊ฐ€๋ด…์‹œ๋‹ค ๐Ÿฅน


! JAVASCRIPT TIP !
1. .scrollIntoView : ํŠน์ •์œ„์น˜๋กœ ํ™”๋ฉด์„ ์ด๋™์‹œํ‚ค๋Š” ๋ฉ”์„œ๋“œ : ์ฆ‰ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„๋•Œ ์›ํ•˜๋Š” ๋‚ด์šฉ์ด ์žˆ๋Š” ์œ„์น˜๋กœ ์ด๋™์‹œ์ผœ์•ผ ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
2. element.getAttribute() : ์„ ํƒํ•œ ์š”์†Œ์˜ ํŠน์ • ์†์„ฑ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฉ”์„œ๋“œ
3. ์Šคํฌ๋กค ์ˆ˜์ง ์œ„์น˜๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” 3๊ฐ€์ง€ ๋ฐฉ๋ฒ• : pageYOffset / scrollY / scrollTop
4. event.preventDefault : ์ผ๋ฐ˜์ ์œผ๋กœ ๋ธŒ๋ผ์šฐ์ €์— ์˜ํ•ด ์ฒ˜๋ฆฌ๋˜๋Š” ๊ธฐ์กด์˜ ์•ก์…˜(๋™์ž‘) ์ฆ‰ ์ด๋ฒคํŠธ ๋ฐœ์ƒ์„ ๋ง‰์•„์ค€๋‹ค. ex) a ํƒœ๊ทธ์˜ ๊ธฐ๋ณธ ์ด๋ฒคํŠธ์ธ href ๋งํฌ ์ด๋™์„ ๋ง‰์•„์„œ ์ด๋™ํ•˜์ง€ ์•Š๊ฒŒ ์„ค์ •.

 const scroll = document.querySelector("#parallax__info .scroll span");

window.addEventListener("scroll", () => {
    //์Šคํฌ๋กค ์ˆ˜์ง ์œ„์น˜๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” 3๊ฐ€์ง€ ๋ฐฉ๋ฒ• : pageYOffset / scrollY / scrollTop : 3๊ฐ€์ง€ ์†์„ฑ์„ ๋ชจ๋‘ ์‚ฌ์šฉํ•ด์•ผ ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €์—์„œ ์œ„์น˜๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.
    let scrollTop = window.pageYOffset || window.scrollY || document.documentElement.scrollTop;
    
    //forEach๋ฌธ - active ์—†์• ๊ณ  ์ฒซ๋ฒˆ์งธ์—๊ฒŒ ๋‹ค์‹œ์ถ”๊ฐ€ ์‹œ์ผœ ์ถ”๊ฐ€๋œ ์š”์†Œ๋งŒ ํšจ๊ณผ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋„๋ก ํ•˜๊ธฐ
    //์Šคํฌ๋กค ์œ„์น˜ ๊ฐ’์ด ์š”์†Œ์˜ offsetTop(์š”์†Œ์˜ ์ˆ˜์ง ๊ฐ’) ๊ฐ’๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์„ ๊ฒฝ์šฐ 
    document.querySelectorAll(".content__item").forEach((el, index) => {
    if (scrollTop >= el.offsetTop -2) { //ํ˜„ ํŽ˜์ด์ง€์—์„œ ์Šคํฌ๋กค์ด ๋งˆ์ง€๋ง‰ ์š”์†Œ๊ฐ’์— ๋ฏธ์น˜์ง€ ๋ชปํ•˜๋Š” ์˜ค๋ฅ˜๊ฐ€ ์žˆ์–ด ์˜ค์ฐจ๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด -2๋ฅผ ํ•ด์ฃผ์–ด์„œ ์˜ค๋ฅ˜๋ฅผ ์™„ํ™”ํ•ด์ฃผ์—ˆ๋‹ค.
        document.querySelectorAll("#parallax__nav li").forEach((li) => {
        li.classList.remove("active"); //li์˜ ์ „์ฒด๋ฅผ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•ด forEach๋ฌธ์„ ํ†ตํ•ด li ๊ฐ’์„ ๋ฝ‘์•„๋‚ด๊ณ  li ์š”์†Œ์— ์„ ์–ธ๋˜์–ด์žˆ๋Š” ๋ชจ๋“  active ์„ ํƒ์ž๋ฅผ ์ง€์›Œ์ค€๋‹ค.
        });
        //์œ„ ์กฐ๊ฑด์ด ์‹คํ–‰๋œ ํ›„ ๋‹ค์‹œ li ์š”์†Œ์˜ ์ฒซ๋ฒˆ์งธ์—๊ฒŒ class๋กœ active๋ฅผ ์„ ์–ธํ•œ๋‹ค.
        //์ธ๋ฑ์Šค์— 1์„ ์ถ”๊ฐ€ํ•œ ์ด์œ ๋Š” ์ธ๋ฑ์Šค๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ. ์ฆ‰ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋ฉด ๋งˆ์ง€๋ง‰ ์˜์—ญ์„ ํฌํ•จํ•˜์ง€ ๋ชปํ•˜๋ฏ€๋กœ 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ธฐ ์œ„ํ•ด ๋งž์ถฐ์ค€ ๊ฒƒ
        document.querySelector("#parallax__nav li:nth-child(" + (index + 1) + ")").classList.add("active");
    }
    });

    //info
    //์Šคํฌ๋กค ์œ„์น˜๊ฐ’์ด ์†Œ์ˆซ์ ์œผ๋กœ ๋‚˜์˜ค๊ธฐ ๋•Œ๋ฌธ์— ์†Œ์ˆซ์ ์„ ์˜ฌ๋ฆผ ๋ฐ ๋ฐ˜์˜ฌ๋ฆผ์„ ํ•ด์ฃผ์–ด ๊ฐ’์ด ๋”ฑ ๋–จ์–ด์ง€๊ฒŒ ํ•ด์ค€๋‹ค
    document.querySelector(".scroll span").innerText = Math.ceil(scrollTop);    //Math.ceil = ๊ฐ’์„ ์˜ฌ๋ ค์„œ ์ˆซ์ž๋กœ ๋ฐ˜ํ™˜์‹œํ‚ค๋Š” 

    //for()
    //์„ ํƒ์ž offset์—๊ฒŒ section์˜ n๋ฒˆ์งธ offsetTop๊ฐ’์„ innerText๋ฅผ ํ†ตํ•ด ์ €์žฅ์‹œํ‚จ๋‹ค.
    for (let i = 1; i <= 9; i++) {
    document.querySelector(".offset" + i).innerText = document.getElementById("section" + i).offsetTop;
    }

    //์Šคํฌ๋กค ์ด๋™
    // ๋งํฌ๋ฅผ ํด๋ฆญํ–ˆ์„ ๋•Œ ๋”ฑ๋”ฑํ•œ ํด๋ฆญ ์ด๋ฒคํŠธ๊ฐ€ ์‹คํ–‰๋˜์ง€ ์•Š๊ณ  ์ƒˆ๋กœ ๋ถ€๋“œ๋Ÿฌ์šด(smooth) ์ด๋ฒคํŠธ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ
    document.querySelectorAll("#parallax__nav li a").forEach((li) =>{
        li.addEventListener("click", (e) =>{
            e.preventDefault(); // event.preventDefault : ํด๋ฆญํ–ˆ์„ ๋•Œ li๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋˜ a์˜ ์†์„ฑ์ธ href(๋งํฌ)๋ฅผ ์‹คํ–‰์‹œํ‚ค์ง€ ์•Š๋Š”๋‹ค.
            document.querySelector(li.getAttribute("href")).scrollIntoView({ 
            behavior: "smooth", //๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์›€์ง์ด๋„๋ก : ์Šคํฌ๋กค์ด ์›€์ง์ผ ๋•Œ.
            });
        });
    });
});


728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css