728x90
๋ฐ์ํ
Javascript parallax Effect
parallax ์ดํํธ ์ค ๋ด์ฉ ๋ํ๋ด๊ธฐ ์ ํ์ ๋๋ค.
HTML
html ์์ค์ ๋๋ค.
<main id="parallax__cont">
<div id="contents">
<section id="section01" class="content__item">
<span class="content__item__num">01</span>
<h2 class="content__item__title">section1</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">
๊ธ์ ์์ธ์ ์ด์ํ๊ฐ ์๊ณ ์์ธ์ ์ด๋ฆ์ด ์ฐ์ฌ์๋ค๊ณ ํด์,
์ธํฐ๋ท์์ ๋ณธ ๋ง์ ์๋ฌด๊ฑฐ๋ ๋ฏฟ์ง ๋ง๋ผ.
</p>
</section>
<!-- section01 -->
<section id="section02" class="content__item">
<span class="content__item__num">02</span>
<h2 class="content__item__title">section02</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">
๋น๋ก ๋ด์ผ ์ง๊ตฌ์ ์ข
๋ง์ด ์จ๋ค ํ๋๋ผ๋ ๋๋ ์ค๋ ํ ๊ทธ๋ฃจ์ ์ฌ๊ณผ๋๋ฌด๋ฅผ ์ฌ๊ฒ ๋ค.
</p>
</section>
<!-- section02 -->
<section id="section03" class="content__item">
<span class="content__item__num">03</span>
<h2 class="content__item__title">section03</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">๊ทธ๋ค์ด ์ฃฝ์์ ๋๋ ค์ํ๋ ๊ฒ์ด ์ด์ํฉ๋๋ค. ์ถ์ด ์ฃฝ์๋ณด๋ค ํจ์ฌ ๋ ์ํ๋ค.</p>
</section>
<!-- section03 -->
<section id="section04" class="content__item">
<span class="content__item__num">04</span>
<h2 class="content__item__title">section04</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">
๋ชจ๋ ๊ฒ์ด ๋ณํ๋ค๋ ๊ฒ์ ๊นจ๋ฌ์ผ๋ฉด ๋ถ์ก์ผ๋ ค ํ ๊ฒ์ด ์๋ค.
</p>
</section>
<!-- section04 -->
<section id="section05" class="content__item">
<span class="content__item__num">05</span>
<h2 class="content__item__title">section05</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">
์ด๋ค ์๊ฐ์ ๋ฐ์๋ค์ด์ง ์๊ณ ์ฆ๊ฒ๊ฒ ํ ์ ์๋ ๊ฒ์ ๊ต์ ์๋ ์ ์ ์ ํ์ง์ด๋ค.
</p>
</section>
<!-- section05 -->
<section id="section06" class="content__item">
<span class="content__item__num">06</span>
<h2 class="content__item__title">section06</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">
์ฒ ํ์ ์ธ์ ๋ ์ฐ๋ฆฌ ๋ ์์ ๋์ฌ ์๋ ๊ทธ ์๋ํ ์ฑ
์ ๊ธฐ๋ก๋์ด ์์ต๋๋ค. ์ฆ, ์ฐ์ฃผ๋ฅผ ์๋ฏธํฉ๋๋ค.
</p>
</section>
<!-- section06 -->
<section id="section07" class="content__item">
<span class="content__item__num">07</span>
<h2 class="content__item__title">section07</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">
ํ๋ณต์ ํ์ด ์ฆ๊ฐํ๊ณ ์ ํญ์ด ๊ทน๋ณต๋๊ณ ์๋ค๋ ๋๋์
๋๋ค.
</p>
</section>
<!-- section07 -->
<section id="section08" class="content__item">
<span class="content__item__num">08</span>
<h2 class="content__item__title">section08</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">์ฌ๋์ ๊ด๊ธฐ๋ ํ๋์ ์ถ๋ณต ์ค ๊ฐ์ฅ ํฐ ๊ฒ์
๋๋ค.</p>
</section>
<!-- section08 -->
<section id="section09" class="content__item">
<span class="content__item__num">09</span>
<h2 class="content__item__title">section09</h2>
<figure class="content__item__imgWrap">
<div class="content__item__img"></div>
</figure>
<p class="content__item__desc">๊ฐํ ์๊ณ ! ๋น์ ์ ์ง๋ฅ์ ์ฌ์ฉํ ์ฉ๊ธฐ๋ฅผ ๊ฐ์ง์ญ์์ค.</p>
</section>
<!-- section09 -->
</div>
</main>
CSS
css ์์ค์ ๋๋ค.
/* parallax__nav */
#parallax__nav {
position: fixed;
right: 20px;
top: 20px;
z-index: 2000;
background-color: rgba(0, 0, 0, 0.4);
padding: 20px 30px;
border-radius: 50px;
transition: top .4s ease;
}
#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(img/effect_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(img/effect_bg09.jpg);
}
.content__item:nth-child(3) .content__item__img {
background-image: url(img/effect_bg09.jpg);
}
.content__item:nth-child(4) .content__item__img {
background-image: url(img/effect_bg09.jpg);
}
.content__item:nth-child(5) .content__item__img {
background-image: url(img/effect_bg09.jpg);
}
.content__item:nth-child(6) .content__item__img {
background-image: url(img/effect_bg09.jpg);
}
.content__item:nth-child(7) .content__item__img {
background-image: url(img/effect_bg09.jpg);
}
.content__item:nth-child(8) .content__item__img {
background-image: url(img/effect_bg09.jpg);
}
.content__item:nth-child(9) .content__item__img {
background-image: url(img/effect_bg09.jpg);
}
.content__item__desc {
font-size: 3vw;
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;
}
#parllax__nav li.active a {
border-radius: 5px;
}
@media (max-width: 800px) {
#parallax__cont {
margin-top: 70vw;
}
#parllax__nav {
padding: 10px;
right: auto;
left: 10px;
top: 10px;
border-radius: 5px;
background: rgba(0, 0, 0, 0.8);
transform: translateY(-50%);
}
#parllax__nav li {
display: block;
margin: 5px;
}
#parllax__nav li a {
font-size: 14px;
padding: 5px;
border-radius: 5px;
height: auto;
line-height: 1;
}
}
/* ํ๋ฒ์ ๋ํ๋๊ธฐ
#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(0.12, 0.72, 0.48, 1.08);
}
#contents > section .content__item__title {
opacity: 0;
transform: translateX(-100px);
transition: all 1s 0.3s cubic-bezier(0.12, 0.72, 0.48, 1.08);
}
#contents > section .content__item__imgWrap {
opacity: 0;
transform: translateY(200px) rotate(30deg) skew(20deg);
transition: all 1s 0.6s cubic-bezier(0.12, 0.72, 0.48, 1.08);
}
#contents > section .content__item__desc {
opacity: 0;
transform: translateX(-200px);
transition: all 1s 0.9s cubic-bezier(0.12, 0.72, 0.48, 1.08);
}
#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);
}
Javascript
Javascript ์์ค์ ๋๋ค.
//์ฌ๊ทํจ์
function scroll(){
let scrollTop = window.pageXOffset || document.documentElement.scrollTop || window.screenY
document.querySelectorAll(".content__item").forEach(item => {
if(scrollTop > item.offsetTop - window.innerHeight/2){
item.classList.add("show");
}
});
requestAnimationFrame(scroll);
}
scroll();
728x90
๋ฐ์ํ
'์ดํํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ฌ๋ผ์ด๋ ์ดํํธ 4. ๋ฒํผ ๋๋ฌ ๋๊ธฐ๊ธฐ (5) | 2022.09.19 |
---|---|
๋ง์ฐ์ค ์ดํํธ 2. ๋ง์ฐ์ค ๋ฐ๋ผ๋ค๋๊ธฐ (GSAP) (3) | 2022.09.19 |
ํจ๋ด๋์ค ์ดํํธ 3. ๋ฉ๋ด ๋ํ๋๊ธฐ / ํ๋ฒํผ (4) | 2022.09.19 |
ํจ๋ด๋ญ์ค ์ดํํธ - 02. ์ฌ์ด๋ ๋ฉ๋ด (1) | 2022.09.13 |
ํจ๋ด๋ ์ค ์ดํํธ - 1. ๋ฉ๋ด ์ด๋ (6) | 2022.09.06 |
๋๊ธ