π± νλ΄λ μ€ ν¨κ³Ό : μ€ν¬λ‘€μ λ΄λ¦΄ λ μμ λνλ΄κΈ°π±
νλ΄λμ€(parallax) μμ°¨λ μλ―Έλ‘ μ¬μ©μκ° μ€ν¬λ‘€λ§μ ν λ λ°°κ²½κ³Ό μμλ§λ€ μλ λ° ν¬κΈ°μ μ°¨μ΄λ₯Ό μ£Όμ΄ μ
체μ μΌλ‘ λκ»΄μ§κ² νλ ν¨κ³Όλ₯Ό λ§ν©λλ€.
μ΄λ² μκ°μλ μ€ν¬λ‘€μ λ΄λ¦΄ λ κ° μΉμ
μ μμλ€μ΄ κ°λ³μ μΌλ‘ μλλ©μ΄μ
λμμ νλλ‘ μ€μ΅ν΄λ³΄κ² μ΅λλ€~!π€©
#1. HTML / CSS μ€μ νκΈ°
βοΈ HTML 보기
<nav id="parallax__nav" class="show">
<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>
<!-- //parallax__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 -->
htmlμ λ©λ΄, κ° μΉμ , μΉμ μ λ€μ΄κ° μ½ν μΈ μ μμ λ±μ κΈ°μ€μΌλ‘ μμ λ‘κ² λ§ν¬μ ν΄μ£Όμλ©΄ λ©λλ€.
βοΈ CSS 보기
/* parallax__nav */
#parallax__nav {
position: fixed;
right: 20px;
top: -200px;
z-index: 2000;
background-color: rgba(95, 95, 95, 0.4);
padding: 20px 30px;
border-radius: 50px;
transition: top 0.4s ease;
}
#parallax__nav.show {
top: 20px;
}
#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;
width: 98%;
margin: 0 auto;
}
.content__item {
width: 1000px;
max-width: 70vw;
margin: 30vw auto;
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;
}
/* κ° μΉμ
ν λ²μ λνλ΄κΈ° */
/* #contents > section {
opacity: 0;
transition: all 1s;
}
#contents > section.show {
opacity: 1;
} */
/* κ° μΉμ
μ μμλ€μ κ°λ³μ μΌλ‘ λνλ΄κΈ° */
#contents > section .content__item__num {
opacity: 0;
transform: translateY(200px);
transition: all 1s 0.1s cubic-bezier(.1,1.01,.78,1.02);
}
#contents > section .content__item__title {
opacity: 0;
transform: translateX(-100px);
transition: all 1s 0.3s cubic-bezier(.1,1.01,.78,1.02);
}
#contents > section .content__item__imgWrap {
opacity: 0;
transform: translateY(200px) rotate(30deg) skew(20deg);
transition: all 1s 0.6s cubic-bezier(.1,1.01,.78,1.02);
}
#contents > section .content__item__desc {
opacity: 0;
transform: translateX(-200px);
transition: all 1s 0.9s cubic-bezier(.1,1.01,.78,1.02);
}
#contents > section.show .content__item__num {
opacity: 0.07;
transform: translateY(0);
}
#contents > section.show .content__item__title {
opacity: 1;
transform: translateX(0);
}
#contents > section.show .content__item__imgWrap {
opacity: 1;
transform: translateY(0) rotate(0) skew(0);
}
#contents > section.show .content__item__desc {
opacity: 1;
transform: translateX(0);
}
/* μ§μμΌ λ : μμκ° νμ§ κΈ°μ€μΌλ‘ μΌμͺ½ μ€λ₯Έμͺ½μΌλ‘ λ°°μΉλμκΈ° λλ¬Έμ λ°©ν₯ μ€μ μ λ§μΆ°μ€ κ². */
#contents > section:nth-child(even) .content__item__title {
transform: translateX(100px);
}
#contents > section:nth-child(even).show .content__item__title {
transform: translateX(0);
}
#contents > section:nth-child(even) .content__item__desc {
transform: translateX(200px);
}
#contents > section:nth-child(even).show .content__item__desc {
transform: translateX(0);
}
/* λ°μν */
@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;
}
}
μΉμ
μ μ½ν
μΈ μμ λ³μ΄ μλ ν λ²μ λμνλλ‘ νλ €λ©΄ κ° μ½ν
μΈ μμλ€μκ² μμ±μ λΆμ¬νμ§ μκ³ κ³΅ν΅ μ νμμκ²λ§ μμ±μ λΆμ¬νλ©΄ λ©λλ€.
λ°λλ‘ κ° μ½ν
μΈ μμλ³λ‘ μμ§μ΄κ² νκ³ μΆλ€λ©΄ κ° μ½ν
μΈ μμλ§λ€ μλλ©μ΄μ
μ μ€μ ν΄μ£Όλ©΄ λ©λλ€.
#2. JAVASCRIPT : μ€ν¬λ¦½νΈλ‘ νλ΄λμ€ ν¨κ³Ό μ£ΌκΈ°
λ¨Όμ μ 체μ μΈ νλ¦μ λ³΄κ³ μ€ν¬λ¦½νΈκ° μ΄λ»κ² μλλλμ§ νμΈν΄λ΄
μλ€! π₯Ή
μ€λ μ€ν¬λ¦½νΈμμ κ°μ₯ μ€μν ν¬μΈνΈλ λ°λ‘ μ¬κ·ν¨μλ₯Ό μ¬μ©νμ¬ μ€ν¬λ¦½νΈλ₯Ό μ§°λ€λ κ²μ
λλ€.
π μ¬κ·ν¨μλ?
μ¬κ·ν¨μλ ν¨μ μμμ μκΈ° μμ μ ν λ² λ νΈμΆνλ ν¨μλ₯Ό μλ―Έν©λλ€. μμ μ λ‘μ§μ ν¨μ μμμ λ°λ³΅νλ€κ° μΌμ 쑰건μ λ§μ‘±νλ©΄ ν¨μ λ°μΌλ‘ λμ μ€νμ λ©μΆ₯λλ€.
λ§μ§λ§ μ€ν 쑰건μ μ€μ νμ§ μμ κ²½μ° ν¨μλ μκΈ° μμ μ 무νλλ‘ λ°λ³΅μ νκ² λλ©° μλ²κ° λ€μ΄λκΈ°λ νλ κΌ μ‘°κ±΄μ μ€μ ν΄μ£Όμ΄μΌ νλ€.
π‘ μ 체 μ€ν¬λ¦½νΈ 보기
//μ¬κ·ν¨μ : μκΈ° μμ μ ν λ² λ μ€ν. μ¦ λ¬΄νλλ‘ μ€νμν¨λ€. μ΄ λ κ·Έλ₯ μ€νμν¬ κ²½μ° μΉμ΄ λ€μ΄λ μ μλ€.
function scroll(){
//λ°λ³΅λ¬Έμ μ¬μ©ν νμ¬ μ€ν¬λ‘€ μμΉ κ°μ ꡬνμ¬ λ³μμ μ μ₯νκΈ°
//μΈκ°μ§λ₯Ό ν λ²μ μμ±ν μ΄μ λ νΈνμ± λ¬Έμ λ‘ μΈν μ€λ₯λ₯Ό λ§κΈ° μν΄μ μ΄λ€. (μμ κ°μ΄ μλνμ§ μμΌλ©΄ λ€μ κ°μΌλ‘ λΆλ¬μ€κΈ°)
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || window.scrollY;
//01
//λͺ¨λ μΉμ
μ μ νν ν forEachλ¬ΈμΌλ‘ λ°λ³΅μν€κΈ°
document.querySelectorAll(".content__item").forEach(item =< {
//02
//νμ¬ μ€ν¬λ‘€ κ°μ΄ κ° μΉμ
μ offsetTopκ° - window.innerHeight(μ¬μ©μ νλ©΄μμ 보μ΄λ λΈλΌμ°μ μμ) κ°μ λ° = νμ¬ λ³΄μ΄λ λΈλΌμ°μ μ λ° λμ΄μ μ΄μ μ€ν¬λ‘€ κ°μ ꡬν μ μλ€.
//μ¦ ν΄λΉ μΉμ
μ€ν¬λ‘€ κ°μ λλ¬νκΈ° μ μ κ·Έ μ΄μ μ€ν¬λ‘€ κ°μμ μλλ©μ΄μ
μ μ€νμν€λλ‘ νμ¬ μΉμ
μ€ν¬λ‘€κ°μ λλ¬ νμ λ μμ ν μΉμ
μ½ν
μΈ λ₯Ό νμΈν μ μλλ‘ νλ€.
if(scrollTop > item.offsetTop - window.innerHeight/2){
item.classList.add("show");
}
});
//03
//requestAnimationFrame() == μ€ν¬λ‘€ μ΄λ²€νΈ λ°μμν€λ λ©μλ μ¦ μ€ν¬λ¦½νΈμμ μ λλ©μ΄μ
μ ꡬνν λ μμ£Ό μ¬μ©
//requestAnimationFrame()μ λΈλΌμ°μ μ μ΅μ νλ λ©μλμ΄λ©° μ μ ν νλ μ μλλ₯Ό μ€νμν¨λ€.(κΈ°λ³Έ 1μ΄ 60νλ μ) λλ¬Έμ μ€ν¬λ‘€ μ΄λ μ λΆλλ½κ³ κ°λ²Όμ΄ μμ§μμ μ€λ€.
requestAnimationFrame(scroll);
}
scroll();
//μ΄λ κ² μ‘°κ±΄(λ©μλ)μ μ€μ ν ν μ€νμν¬ κ²½μ° λ©λͺ¨λ¦¬λ₯Ό μ κ² μ°¨μ§νμ¬ μΉμ΄ λ€μ΄λμ§ μλλ€.
1. λͺ¨λ μΉμ
μ μ νν ν λ°λ³΅λ¬Έ λ§λ€κΈ°
2. λ°λ³΅λ¬Έ μμ 쑰건문μ ν΅ν΄ ν΄λΉ μΉμ
μμμ λ° μ λμ μ΄μ μμμ μ€ν¬λ‘€μ΄ μ¬ κ²½μ° μλλ©μ΄μ
μ μ€νμμΌ ν΄λΉ μΉμ
μμμ μ€ν¬λ‘€μ΄ μ¬ κ²½μ° μ½ν
μΈ κ° μ¨μ ν λ€ λ³΄μ΄λλ‘ μ€μ ν©λλ€.
3. requestAnimationFrame()λ©μλλ₯Ό ν΅ν΄ scroll ν¨μκ° λ°λ³΅μ΄ λκ³ λ§μ§λ§ μ λλ©μ΄μ
μ΄ λλ κ²½μ° λ°λ³΅μ μ€λ¨νλλ‘ ν©λλ€.
'EFFECT' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[EFFECT] μ¬λΌμ΄λ ν¨κ³Ό 04 : λ²νΌμΌλ‘ μ΄λ―Έμ§ μ΄λμν€κΈ°! (2) | 2022.09.19 |
---|---|
[EFFECT] λ§μ°μ€ ν¨κ³Ό 02 : 컀μ λ°λΌλ€λκΈ° (2) | 2022.09.19 |
[EFFECT] νλ΄λ μ€ ν¨κ³Ό 03 : topλ²νΌ ꡬνκ³Ό λ©λ΄ μ¨κΉ ν¨κ³Ό (4) | 2022.09.14 |
[EFFECT] νλ΄λ μ€ ν¨κ³Ό02 : μ€λ¬΄μ€~ν λ²νΌ μ΄λ (1) | 2022.09.14 |
[EFFCET] νλ΄λ μ€(parallax) ν¨κ³Ό : λ©λ΄ μ΄λ (3) | 2022.09.07 |
λκΈ