
โญ๏ธ Parallax Scrolling ํจ๋ด๋์ค ์คํฌ๋กค๋ง 05 : ๋ถ๋๋ฌ์ด ์ด๋ & ์์์ ์ด์ง๊ฐ ํจ๊ณผ & ํ๋จ top ๋ฒํผ ์จ๊น โญ๏ธ
01. Parallax Scrolling
ํจ๋ด๋์ค(Parallax)๋ '์์ฐจ'๋ฅผ ๋ปํ๋ ๋จ์ด๋ก, ๋ฉ๋ฆฌ ์๋ ๋ฌผ์ฒด๋ ์ฒ์ฒํ ์์ง์ด๊ณ ๊ฐ๊น์ด ์๋ ๋ฌผ์ฒด๋ ๋น ๋ฅด๊ฒ ์์ง์ด๋ ํ์์ ์๋ฏธํฉ๋๋ค.
ํจ๋ด๋์ค ์คํฌ๋กค๋ง (Parallax Scrolling) ๊ธฐ์ ์ ๋ฐฐ๊ฒฝ ๋๋ ์ค๋ธ์ ํธ์ ๋ ์ด์ดํ, ์คํฌ๋กค๊ณผ ์ ๋๋ฉ์ด์
์ ์๋ ์กฐ์ ์ ํตํด ๊น์ด์ ๋ํ ์ฐฉ์๋ฅผ ๋ณด์ฌ์ฃผ๋ ๊ธฐ์ ์
๋๋ค.
์ด ๊ธฐ์ ์ ํ ํ์ด์ง๋ก ๊ตฌ์ฑํ ์ ์์ผ๋ฉฐ, ์๊ฐ์ ์ธ ๋ชฐ์
๊ฐ์ ์ฃผ๊ณ ํจ๊ณผ์ ์ธ ์คํ ๋ฆฌํ
๋ง์ ๊ฐ๋ฅํ๊ฒ ํ๋ ์ฅ์ ์ด ์์ต๋๋ค.
๋ค๋ง ๋ด์ฉ์ด ๋๋ฌด ๊ธธ ๊ฒฝ์ฐ์๋ ์ฌ์ฉ์๊ฐ ์ง๋ฃจํจ์ด๋ ๋ถํธํจ์ ๋๋ ์ ์๊ณ , ํ๋ฉด ๊ตฌ์ฑ์ด ๋ณต์กํด์ง๋ฉฐ ๋ง์ ๋ฆฌ์์ค๋ก ์ธํด ๋ก๋ฉ ์๋๊ฐ ๋๋ฆด ์ ์์ต๋๋ค.
02. ํจ๋ด๋์ค ์คํฌ๋กค๋ง ๋ง๋ค์ด๋ณด๊ธฐ : ๋ชฉํ
๐ง ๋ธ๋ผ์ฐ์ ์ ๋งจ ์๋์ ๋๋ฌํ๋ฉด, top ๋ฒํผ์ด ์จ๊ฒจ์ ธ ์๋ค๊ฐ ๋์ค๋๋ก ์ค์ ํฉ๋๋ค.
๐ง top ๋ฒํผ์ ๋๋ฌ ์ด๋ํ๊ฒ ๋ ๋, ํ๋ฉด์ด ๋ถ๋๋ฝ๊ฒ ์ด๋๋๋ ํจ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋๋ค.
๐ง section ์ ์์๋ค(์ซ์, ์ด๋ฏธ์ง, ๊ธ)์ด ์คํฌ๋กคํ๋ ๊ธธ์ด์ ๋น๋กํ์ฌ ์ด์ง ์์ง์ด๋ฉด์ ์ด์ง๊ฐ์ด ๋๊ปด์ง๋ ํจ๊ณผ๋ฅผ ํํํฉ๋๋ค.
[1] top ๋ฒํผ ๋ง๋ค๊ธฐ (html)
div ํ๊ทธ๋ฅผ ๋ง๋ค๊ณ , css ์ script ์ ๊ฒฝ๋ก ์ค์ ์ ์ํด id๋ก ์ด๋ฆ์ ์ ํฉ๋๋ค.
___ ์ฐธ๊ณ ํ๊ธฐ ___
`1 a href ์ class ="ํด๋์ค๊ฐ" ๋๋ id ="์์ด๋๊ฐ" ์ ๋ฃ์ด์ฃผ๋ฉด ๋งํฌ ์ด๋์ด ๊ฐ๋ฅํฉ๋๋ค.
<div id="parallax__top">top</div> <!-- //parallax__top -->
[2] top ๋ฒํผ ๋์์ธํ๊ธฐ (css)
๋ธ๋ผ์ฐ์ ํ๋ฉด์ ์ด๋ป๊ฒ ๋ณด์ฌ์ง๋์ง ๊ณ์ ํ์ธํ๋ฉด์ ๋์์ธํฉ๋๋ค.
#parallax__top { position: fixed; /* ์๋์ ๋ณด์ด์ง ์๊ฒ ๊ณ ์ ์์ผ ๋๊ณ script ๊ณผ์ ์ผ๋ก ๋์ฐ๊ณ ์ํจ */ left: 50%; right: 20px; bottom: -220px; /* parallax__top ์ show ๊ฐ ์ ๋ถ์์ ๋๋ ์จ๊ฒจ์ฃผ๊ธฐ ์ํด - ๊ฐ์ ์ค */ transform: translateX(-50%); /* top ๋ฒํผ์ด X์ถ(๊ฐ๋ก)์ ์ค๊ฐ์ ์์นํ๋๋ก */ z-index: 10000; /* top ๋ฒํผ์ ๋๋ฌ์ ์๋ํด์ผ ํ๋ฏ๋ก, ๋ ์ด์์์ ๋งจ ์์ชฝ(ํ๋ฉด)์ ์์น์ํด */ width: 40px; /* parallax__top ๊ฐ ์ฐจ์งํ ์์ญ์ ๋๋น ์ค์ */ height: 40px; /* parallax__top ๊ฐ ์ฐจ์งํ ์์ญ์ ๋์ด ์ค์ */ background: rgba(0,0,0,0.4); /* rgba : ํฌ๋ช
์ ์ง์ */ text-align: center; /* ํ
์คํธ ์ค์ ์ ๋ ฌ */ line-height: 40px; /* ์ค๊ฐ๊ฒฉ : ๊ธฐ์ค ๋์ด */ color: #fff; /* ๊ธ์์ */ border-radius: 50%; /* ๋๋น์ ๋์ด๊ฐ ๊ฐ์ ๋ ํ
๋๋ฆฌ ๊ณก๋ฅ ์ด 50% ์ด๋ฉด ์ ๋ชจ์์ด ๋ง๋ค์ด์ง */ padding: 10px; /* ์์ชฝ ์ฌ๋ฐฑ */ cursor: pointer; /* ์ปค์ ๋ชจ์ ์ง์ */ transition: all 0.3s; } #parallax__top.show { bottom: 20px; /* parallax__top ์ show ๊ฐ ๋ถ์์ ๋ ๋์ค๊ฒ ํ๊ธฐ ์ํจ */ } #parallax__top:hover { /* ๋ง์ฐ์ค ์ค๋ฒ ํจ๊ณผ */ background: #fff; color: #000; }
[3] ๋ด์ฉ ๊ตฌ์กฐ ์ง๊ธฐ (html)
1) main ํ๊ทธ > div (contents) > section > [ span (๋ฉ๋ด ๋ฒํธ) | h2 (๋ฉ๋ด ์ด๋ฆ) | { figure > div (์ด๋ฏธ์ง) } | p (๋ด์ฉ ๊ธ) ] * 9 (๋ฉ๋ด ๊ฐฏ์)
2) css ์ script ์ ๊ฒฝ๋ก ์ค์ ์ ์ํด, id ์ class ๋ก ์ด๋ฆ์ ์ ํฉ๋๋ค.
<main id="parallax__cont"> <div id="contents"> <section id="section1" class="contents__item"> <span class="contents__item__num">01</span> <h2 class="contents__item_title">section1</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 1</p> </section> <!-- //section1 --> <section id="section2" class="contents__item"> <span class="contents__item__num">02</span> <h2 class="contents__item_title">section2</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 2</p> </section> <!-- //section2 --> <section id="section3" class="contents__item"> <span class="contents__item__num">03</span> <h2 class="contents__item_title">section3</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 3</p> </section> <!-- //section3 --> <section id="section4" class="contents__item"> <span class="contents__item__num">04</span> <h2 class="contents__item_title">section4</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 4</p> </section> <!-- //section4 --> <section id="section5" class="contents__item"> <span class="contents__item__num">05</span> <h2 class="contents__item_title">section5</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 5</p> </section> <!-- //section5 --> <section id="section6" class="contents__item"> <span class="contents__item__num">06</span> <h2 class="contents__item_title">section6</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 6</p> </section> <!-- //section6 --> <section id="section7" class="contents__item"> <span class="contents__item__num">07</span> <h2 class="contents__item_title">section7</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 7</p> </section> <!-- //section7 --> <section id="section8" class="contents__item"> <span class="contents__item__num">08</span> <h2 class="contents__item_title">section8</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 8</p> </section> <!-- //section8 --> <section id="section9" class="contents__item"> <span class="contents__item__num">09</span> <h2 class="contents__item_title">section9</h2> <figure class="contents__item__imgWrap"> <div class="contents__item__img"></div> </figure> <p class="contents__item__desc">๋ด์ฉ ๊ธ 9</p> </section> <!-- //section9 --> </div> </main> <!-- //main -->
[4] ๋ด์ฉ ๊ตฌ์กฐ ๋์์ธํ๊ธฐ (css)
๋ธ๋ผ์ฐ์ ํ๋ฉด์ ์ด๋ป๊ฒ ๋ณด์ฌ์ง๋์ง ๊ณ์ ํ์ธํ๋ฉด์ ๋์์ธํฉ๋๋ค.
#parallax__cont { max-width: 1600px; /* ์ต๋ ๋๋น ์ค์ */ width: 98%; margin: 0 auto; /* background-color: rgba(255, 255, 255, 0.1); ์์๋ก ์ค ๊ฐ, css ์ค์ ํ๋ฉฐ ๋ธ๋ผ์ฐ์ ํ๋ฉด ํ์ธ ํ ์ง์๋๋ค. */ } .contents__item { width: 1000px; /* section ์ด ์ฐจ์งํ ๋๋น ์ค์ */ max-width: 70vw; /* vw : ๋ทฐํฌํธ์ ๋น์จ๋ก */ margin: 30vw auto; /* background-color: rgba(255, 255, 255, 0.1); ์์๋ก ์ค ๊ฐ, css ์ค์ ํ๋ฉฐ ๋ธ๋ผ์ฐ์ ํ๋ฉด ํ์ธ ํ ์ง์๋๋ค. */ text-align: left; /* ํ
์คํธ ์ผ์ชฝ ์ ๋ ฌ */ margin-right: 0; position: relative; /* contents__item__num ์ position ์ ๋ํ ๊ธฐ์ค์ ์ค์ (์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ ๊ธฐ์ค์ ์ธ ๋ธ๋ผ์ฐ์ ์ผ์ชฝ ๋งจ ์์ ๋ชจ๋ ๊ฒน์ณ์ง) */ padding-top: 9vw; } .contents__item:nth-child(even) { /* : ์ ์์ child( ~ ๋ฒ์งธ ) -> 2n : 2์ ๋ฐฐ์, 2n+1 : 3์ ๋ฐฐ์, even : ์ง์, odd : ํ์ */ margin-left: 0; text-align: right; /* ํ
์คํธ ์ค๋ฅธ์ชฝ ์ ๋ ฌ */ } .contents__item__num { font-size: 35vw; /* ๊ธ์ ํฌ๊ธฐ */ font-family: 'Lato'; /* ๊ธ์์ฒด */ font-weight: 100; /* ๊ธ์ ๋๊ป */ position: absolute; /* ์ซ์๊ฐ ์ด๋ฏธ์ง์ ๊ฒน์น๋๋ก ์์น๋ฅผ ์ค์ ํด์ค; ๋ถ๋ชจ ์์ญ์ ๊ธฐ์ค์ผ๋ก ์ค์ ๋์ด์ผ ํจ -> relative ์ค์ */ left: -6vw; /* ์์น ์ค์ : ์ผ์ชฝ ๊ฐ๊ฒฉ ์ค์ */ top: -13vw; /* ์์น ์ค์ : ์์ชฝ ๊ฐ๊ฒฉ ์ค์ */ opacity: 0.07; /* ํฌ๋ช
๋ */ z-index: -2; /* ๋ ์ด์์์์ ๊ฒน์ณ์ง ์ซ์๊ฐ ์ด๋ฏธ์ง ์๋(๋ค)์ ์์นํ๋๋ก */ } .contents__item:nth-child(even) .contents__item__num { left: auto; /* left ๊ฐ ์ด๊ธฐํ; ๊ธฐ์ค์ ์ด right ๋ก ๋ฐ๋ */ right: -8vw; /* ์์น ์ค์ : ์ค๋ฅธ์ชฝ ๊ฐ๊ฒฉ ์ค์ */ } .contents__item_title { font-weight: 400; text-transform: capitalize; /* ๋จ์ด์ ์ฒซ๋ฒ์งธ ๊ธ์๋ฅผ ๋๋ฌธ์๋ก ๋ฐ๊ฟ์ค; section -> Section */ } .contents__item__imgWrap { width: 100%; padding-bottom: 56.25%; /* ๊ฐ์์ผ๋ก ์ด๋ฏธ์ง ์์ญ์ ๋ง๋ค์ด์ค -> ์ด๋ฏธ์ง๋ฅผ ์ถ๋ ฅํ ์ ์์ */ background: #000; position: relative; /* contents__item__img ์ position ์ ๋ํ ๊ธฐ์ค์ ์ค์ */ overflow: hidden; /* ์ด๋ฏธ์ง๊ฐ ์์ญ ๋ฐ์ผ๋ก ๋์ณ ๋๊ฐ๋ ๊ฒ์ ๋ง์์ค */ z-index: -1; } .contents__item__img { background-repeat: no-repeat; /* ๊ธฐ๋ณธ์ผ๋ก ์ค์ ๋ ์ด๋ฏธ์ง ๋ฐ๋ณต ์ฑ์์ ํด์ */ background-position: center center; /* ์ด๋ฏธ์ง๊ฐ ์ ๊ฐ์ด๋ฐ์ ์์นํ๋๋ก ์ง์ ex) left top, right center, center bottom ๋ฑ */ background-size: cover; /* ์์์ ํฌ๊ธฐ์ ๋ง์ถฐ์ ์ด๋ฏธ์ง๊ฐ ๋ฎ์ด๋๋ก ์ด๋ฏธ์ง ํฌ๊ธฐ ์ค์ */ width: 110%; height: 110%; position: absolute; /* ์์น๋ฅผ ์ค์ ํด์ค; ๋ถ๋ชจ ์์ญ์ ๊ธฐ์ค์ผ๋ก ์ค์ ๋์ด์ผ ํจ -> relative ์ค์ */ left: -5%; top: -5%; filter: saturate(0%); /* ์ด๋ฏธ์ง ํํฐ : ํ๋ฐฑ (0% ํ๋ฐฑ, 50% ํ๋ฐฑ ๋ฐ ์๊น ๋ฐ) */ transition: all 1s; } /* ๊ฐ ์น์
์ ์ด๋ฏธ์ง๋ก ๋ฐฐ๊ฒฝ ๋ฃ๊ธฐ */ .contents__item:nth-child(1) .contents__item__img { /* contents__item ์ ์ฒซ๋ฒ์งธ ์์ contents__item__img ์๊ฒ ์ด๋ฏธ์ง๋ฅผ ๋ฃ์ด๋ผ */ background-image: url(../assets/img/parallax01.jpg); } .contents__item:nth-child(2) .contents__item__img { background-image: url(../assets/img/parallax02.jpg); } .contents__item:nth-child(3) .contents__item__img { background-image: url(../assets/img/parallax03.jpg); } .contents__item:nth-child(4) .contents__item__img { background-image: url(../assets/img/parallax04.jpg); } .contents__item:nth-child(5) .contents__item__img { background-image: url(../assets/img/parallax05.jpg); } .contents__item:nth-child(6) .contents__item__img { background-image: url(../assets/img/parallax06.jpg); } .contents__item:nth-child(7) .contents__item__img { background-image: url(../assets/img/parallax07.jpg); } .contents__item:nth-child(8) .contents__item__img { background-image: url(../assets/img/parallax08.jpg); } .contents__item:nth-child(9) .contents__item__img { background-image: url(../assets/img/parallax09.jpg); } .contents__item__desc { font-size: 2vw; font-weight: 600; color: #FFFFF0; text-shadow: 1px 1px 1px #222; /* ํ
์คํธ ๊ทธ๋ฆผ์ ํจ๊ณผ : ๊ฐ๋กpx, ์ธ๋กpx, ๋ฒ์ง ์ ๋, ์๊น -> ์ด์ ๊ฐ์ ์์ฑ ๊ฐ์ ์ผํ๋ก ๊ตฌ๋ถํ์ฌ ์ฌ๋ฌ ๊ฐ ์
๋ ฅํ๋ฉด ์ฌ๋ฌ ๊ฐ์ ๊ทธ๋ฆผ์๊ฐ ์๊น*/ line-height: 1.4; margin-top: -2vw; margin-left: -5vw; word-break: keep-all; /* ์ด์ ๋จ์๋ก ๋์ด์ง๋ฉฐ ์ค๋ฐ๊ฟ์ด ๋๋๋ก ์ค์ */ } .contents__item:nth-child(even) .contents__item__desc { margin-left: auto; /* ์ผ์ชฝ ๋ฐ๊นฅ ์ฌ๋ฐฑ ์ด๊ธฐํ; ๊ธฐ์ค์ ์ด ์ค๋ฅธ์ชฝ ๋ฐ๊นฅ ์ฌ๋ฐฑ์ผ๋ก ๋ฐ๋ */ margin-right: -4vw; }
[5] parallax__info ํ์ธ์นธ ๋ง๋ค๊ธฐ (html)
1) ์๋ฉํฑ ๊ตฌ์กฐ๋ฅผ ์ํด aside ํ๊ทธ > div ํ๊ทธ > span ํ๊ทธ๋ฅผ ์์ฑํฉ๋๋ค.
2) css ์ script ์ ๊ฒฝ๋ก ์ค์ ์ ์ํด, id ์ class ๋ก ์ด๋ฆ์ ์ ํฉ๋๋ค.
<aside id="parallax__info"> <div class="scroll">scrollTop: <span>0</span>px</div> <div class="info"> <ul> <li>( scrollTop - section$ ๋์ด๊ฐ ) * 0.07</li> <li>#(sT - s1) * 0.07 : <span class="offset1">0</span>px</li> <li>#(sT - s2) * 0.07 : <span class="offset2">0</span>px</li> <li>#(sT - s3) * 0.07 : <span class="offset3">0</span>px</li> <li>#(sT - s4) * 0.07 : <span class="offset4">0</span>px</li> <li>#(sT - s5) * 0.07 : <span class="offset5">0</span>px</li> <li>#(sT - s6) * 0.07 : <span class="offset6">0</span>px</li> <li>#(sT - s7) * 0.07 : <span class="offset7">0</span>px</li> <li>#(sT - s8) * 0.07 : <span class="offset8">0</span>px</li> <li>#(sT - s9) * 0.07 : <span class="offset9">0</span>px</li> </ul> </div> </aside> <!-- //parallax__info -->
[6] ์์น ํ์ธ์นธ ๋์์ธํ๊ธฐ (css)
๋ธ๋ผ์ฐ์ ํ๋ฉด์ ์ด๋ป๊ฒ ๋ณด์ฌ์ง๋์ง ๊ณ์ ํ์ธํ๋ฉด์ ๋์์ธํฉ๋๋ค.
#parallax__info { position: fixed; /* ์ผ์ชฝ ์๋์ ๊ณ ์ ์ํด */ left: 20px; bottom: 20px; z-index: 2000; /* ๊ฐ๋ ค์ง์ง ์๋๋ก ๋งจ ์์ชฝ(ํ๋ฉด)์ ์์น์ํด */ background: rgba(0, 0, 0, 0.4); color: #fff; padding: 20px; border-radius: 10px; } #parallax__info li, .scroll { line-height: 1.4; /* parallax__info li ์ .scroll ์ ๋ด์ฉ ๊ธ์์ ๋ํ ์ค๊ฐ๊ฒฉ ์ค์ */ }
[7] ์ด์ง๊ฐ ํจ๊ณผ ๋ฐ ๋ณํ๋ ๊ฐ ๊ณ์ฐํ์ฌ ์ถ๋ ฅํ๊ธฐ (script)
1) ๊ฐ์ ์ด๋ป๊ฒ ๊ฐ์ ธ์์ผ ํ ์ง ์๊ฐํด๋ณด๊ณ , ๊ณ์ฐ ๋ฐฉ๋ฒ์ ๊ตฌ์ํด๋ด
๋๋ค.
2) ๊ฐ์ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ, ๊ณ์ฐ ๋ฐฉ๋ฒ์ ๋ค์ํ๊ฒ ์๊ฐํด๋ณด๊ณ ์ฌ๋ฌ ๊ฐ์ง๋ก ์ถ๋ ฅํด๋ด
์๋ค.
// scrollTop ๊ฐ & top ๋ฒํผ window.addEventListener("scroll", () => { // ๋ธ๋ผ์ฐ์ ๋ฅผ ์คํฌ๋กค ํ์ ๋, // let scrollTop = window.pageYOffset; // 3๊ฐ์ง ์์ // let scrollTop = window.scrollY; // ๋ชจ๋ ๊ฐ์ ๊ฐ์ ๊ฐ์ง๋ค. // let scrollTop = document.documentElement.scrollTop; // ๋ธ๋ผ์ฐ์ ์์ ์ง์ํ๋ ๊ฒ์ด ๋ค๋ฅผ ์ ์๊ธฐ ๋๋ฌธ์, ์๋์ ๊ฐ์ด ํฉ์ณ์ ํํํจ // scrollTop ๋ณ์ ์์ ๋ธ๋ผ์ฐ์ ๊ธฐ์ค์ ์ธ๋ก ์คํฌ๋กค ๊ฐ์ ์ ์ฅํ์์ค. |๋๋| let scrollTop = window.pageYOffset || window.scrollY || document.documentElement.scrollTop; // ๊ทธ๋ฆฌ๊ณ scrollTop ๊ฐ์ parallax__info .scroll span ์์ ์ถ๋ ฅํ์์ค. document.querySelector("#parallax__info .scroll span").innerText = Math.round(scrollTop); // ์์์ ; ๋ด๋ฆผ Math.floor( ), ์ฌ๋ฆผ Math.ceil( ), ๋ฐ์ฌ๋ฆผ Math.round( ) // script ๋งจ ์์ชฝ์ const scroll = document.querySelector("#parallax__info .scroll span"); ์ด๋ ๊ฒ scroll ์์ ์ค์ ํ, // scroll.innerText = Math.round(scrollTop); ์ด๋ ๊ฒ ์
๋ ฅํด๋ ์ถ๋ ฅ๋จ // ์จ๊ฒจ์ ธ ์๋ top ๋ฒํผ ๋ํ๋ด๊ธฐ : scrollTop ๊ฐ์ด (๋ฌธ์ ์ ์ฒด ๋์ด - ํ์ฌ ๋ณด์ฌ์ง๋ ๋ธ๋ผ์ฐ์ ๋์ด) ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ ๊ฒฝ์ฐ์ ์๋์ํค๊ธฐ // scrollTop ๊ฐ์ด (๋ฌธ์ ์ ์ฒด ๋์ด - ํ์ฌ ๋ณด์ฌ์ง๋ ๋ธ๋ผ์ฐ์ ๋์ด) ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๋ค๋ ๊ฒ์ ์คํฌ๋กค์ด ๋ฌธ์์ ๋์ ๋๋ฌํ๋ค๋ ์๋ฏธ if(scrollTop >= document.body.scrollHeight - window.innerHeight){ // scrollTop ๊ฐ์ด (๋ฌธ์ ์ ์ฒด ๋์ด - ํ์ฌ ๋ณด์ฌ์ง๋ ๋ธ๋ผ์ฐ์ ๋์ด) ๊ฐ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ ๋, document.querySelector("#parallax__top").classList.add("show"); // parallax__top ์ ํด๋์ค์ show ๋ฅผ ์ถ๊ฐํ๊ณ } else { // ๊ทธ๋ ์ง ์์ผ๋ฉด document.querySelector("#parallax__top").classList.remove("show"); // parallax__top ์ ํด๋์ค์ show ๋ฅผ ์ ๊ฑฐํ์์ค. } }); // top ๋ฒํผ ๋๋ฅด๋ฉด ์คํฌ๋กค์ด ๋งจ ์๋ก ์ด๋ํ๋๋ก ์๋์ํค๊ธฐ document.querySelector("#parallax__top").addEventListener("click", () => { // top ๋ฒํผ์ ํด๋ฆญํ์ ๋, window.scrollTo({left: 0, top: 0, behavior: "smooth"}); }); // ๋ธ๋ผ์ฐ์ ์ (left = x ์ขํ 0, top = y์ขํ 0) ์์น๋ก ์คํฌ๋กค์ ์ด๋์ํค๊ณ , ๋์์ "smooth" ๋ถ๋๋ฝ๊ฒ ์คํฌ๋กค๋์ด ๋์ด๊ฐ๋๋ก ์ค์ // scrollTo() : (์ ๋ ์ขํ) ์ผ์ชฝ ์๋จ ๋ชจ์๋ฆฌ๋ถํฐ ์์ํ๋ ์ ์ฒด ํฌ๊ธฐ์ ๋ธ๋ผ์ฐ์ ๋ฅผ ๊ธฐ์ค์ผ๋ก, ์ง์ ๋ ์ขํ๋ก ์คํฌ๋กค์ ์ด๋์ํด // parallax__info ์ ๋ค์ด๊ฐ๋ ๊ฐ & ์ ๋๋ฉ์ด์
์คํ์ํค๊ธฐ // ์ด์ง๊ฐ ํจ๊ณผ (์ฌ๊ทํจ์) function scroll(){ // scroll ํจ์๋ let scrollTop = window.pageYOffset || window.scrollY || document.documentElement.scrollTop; // scrollTop ๋ณ์ ์์ ๋ธ๋ผ์ฐ์ ๊ธฐ์ค์ ์ธ๋ก ์คํฌ๋กค ๊ฐ์ด ์์ ๋, // document.querySelector("#parallax__info .scroll span").innerText = Math.round(scrollTop); // scrollTop ๊ฐ ์ถ๋ ฅ, ์์ ํด์ค // i ๊ฐ 1๋ถํฐ 9๊น์ง ์ฆ๊ฐํ ๋, for (let i=1; i<=9; i++) { let offTop = document.getElementById("section" + i).offsetTop; document.querySelector(".offset" + i).innerText = Math.round(( scrollTop - offTop ) * 0.07); // document.querySelector(".offset" + i).innerText = scrollTop - document.getElementById("section" + i).offsetTop; } // ์์ (offset + i) ์์ ์ถ๋ ฅํ์์ค. = scrollTop ์์ ์์ด๋ (section + i) ์์์ Y์ถ ๊ฐ(๋ฌธ์ ๊ธฐ์ค)์ ๋บ ๊ฐ์ // .contents__item(section ์์ญ) ์ค์์ document.querySelectorAll(".contents__item").forEach(item => { const target1 = item.querySelector(".contents__item__num"); // ์ซ์์ ๋ํ ์์ ์ค์ const target2 = item.querySelector(".contents__item__img"); // ์ด๋ฏธ์ง์ ๋ํ ์์ ์ค์ const target3 = item.querySelector(".contents__item__desc"); // ๋ด์ฉ๊ธ์ ๋ํ ์์ ์ค์ let offset1 = (scrollTop - item.offsetTop) * 0.04; // ์์ง์ด๋ ๊ฐ์ ๋ํ ๋ณ์ ์ค์ let offset2 = (scrollTop - item.offsetTop) * 0.07; let offset3 = (scrollTop - item.offsetTop) * 0.05; // target1.style.transform = `translateY(${-offset1}px)`; // ์ซ์๋ฅผ offset1 ๋งํผ ์ฌ๋ ค์ค // target2.style.transform = `translateY(${offset2}px)`; // ์ด๋ฏธ์ง๋ฅผ offset2 ๋งํผ ๋ด๋ ค์ค // target3.style.transform = `translateX(${offset3}px)`; // ๋ด์ฉ๊ธ์ offset3 ๋งํผ ์ค๋ฅธ์ชฝ์ผ๋ก ๋ฐ์ด์ค gsap.to(target1, {duration: .5, y: -offset1, ease:"power1.out"}) // GSAP ํ์ฉํ๊ธฐ gsap.to(target2, {duration: .3, y: offset2}) gsap.to(target3, {duration: .5, x: offset3}) }); requestAnimationFrame(scroll); /* ์ ๋๋ฉ์ด์
์ ๊ตฌํํ๊ธฐ ์ํด ์ต์ ํ๋ ํจ์: ์์ง์์ด ๋ถ๋๋ฝ๊ณ ๋ฉ๋ชจ๋ฆฌ๋ ๋ ์ฐจ์งํจ, 1์ด์ 60๋ฒ ์คํ์ํด */ } scroll();
๋๊ธ