728x90
반응형
패럴랙스 04
스크롤바 컴퓨터마다 안되는게 있을수 있으니 3개를 적어줍니다.
let scrollTop = window.pageYOffset || window.scrollY || document.documentElement.scrollTop;
script 코드
// 재귀함수
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); //움직임이 부드럽다. 1분에 60번 실행 메모리 적게 차지함.
}
scroll();
CSS
코드 보기
/* .parallax__nav */
#parallax__nav {
position: fixed;
right: 20px;
top: 20px;
z-index: 20000;
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;
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;
/* background-color: rgba(255, 255, 255, 0.1); */
}
.content__item {
width: 1000px;
max-width: 70vw;
margin: 30vw auto;
/* background-color: rgba(255, 255, 255, 0.3); */
text-align: left;
margin-right: 0;
position: relative;
padding-top: 7vw;
}
/* .content__item 의 짝수만 선택 even , 2n = +,* 가능 */
.content__item:nth-child(even) {
margin-left: 0;
text-align: right;
}
/* left 값 초기화 */
.content__item:nth-child(even) .content__item__num {
left: auto;
right: -5vw;
}
.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__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;
background: url(../assets/img3/effect_bg01-min.jpg);
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
width: 110%;
height: 110%;
left: -5%;
top: -5%;
filter: saturate(0%);
transition: all 1s;
}
.content__item:nth-child(1) .content__item__img {
background-image: url(../assets/img3/effect_bg01-min.jpg);
}
.content__item:nth-child(2) .content__item__img {
background-image: url(../assets/img3/effect_bg02-min.jpg);
}
.content__item:nth-child(3) .content__item__img {
background-image: url(../assets/img3/effect_bg03-min.jpg);
}
.content__item:nth-child(4) .content__item__img {
background-image: url(../assets/img3/effect_bg04-min.jpg);
}
.content__item:nth-child(5) .content__item__img {
background-image: url(../assets/img3/effect_bg05-min.jpg);
}
.content__item:nth-child(6) .content__item__img {
background-image: url(../assets/img3/effect_bg06-min.jpg);
}
.content__item:nth-child(7) .content__item__img {
background-image: url(../assets/img3/effect_bg07-min.jpg);
}
.content__item:nth-child(8) .content__item__img {
background-image: url(../assets/img3/effect_bg08-min.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;
}
@media (max-width: 800px) {
#parallax__cont {
margin-top: 70vw;
}
#parallax__nav {
padding: 10px;
right: auto;
left: 10px;
top: 10px;
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;
}
}
/* 한번에 나타나기 */
/* #contents>section {
opacity: 0;
transition: all 1s;
}
#contents>section {
opacity: 1;
} */
/* 개별적으로 나타나기 */
#contents>section .content__item__num {
opacity: 0;
transform: translateY(200px);
transition: all 1s 0.1s cubic-bezier(0.01, 0.11, 0.6, 0.88);
}
#contents>section .content__item__title {
opacity: 0;
transform: translateX(-100px);
transition: all 1s 0.3s cubic-bezier(0.01, 0.11, 0.6, 0.88);
}
#contents>section .content__item__imgWrap {
opacity: 0;
transform: translateY(200px) rotate(30deg) skew(20deg);
transition: all 1s 0.6s cubic-bezier(0.01, 0.11, 0.6, 0.88);
}
#contents>section .content__item__desc {
opacity: 0;
transform: translateX(-200px);
transition: all 1s 0.9s cubic-bezier(0.01, 0.11, 0.6, 0.88);
}
#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);
}
HTML
코드 보기
<body class="img01">
<header id="header">
<h1>Javascript parallax Effect01</h1>
<p>패럴랙스 이펙트 - 메뉴 이동</p>
<ul>
<li class="active"><a href="parallaxEffect01.html">1</a></li>
<li><a href="parallaxEffect02.html">2</a></li>
<li><a href="parallaxEffect03.html">3</a></li>
<li><a href="parallaxEffect04.html">4</a></li>
<li><a href="parallaxEffect05.html">5</a></li>
<li><a href="parallaxEffect06.html">6</a></li>
<li><a href="parallaxEffect07.html">7</a></li>
</ul>
</header>
<!-- //header -->
<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>
<!-- parallax__nav -->
<main id="parallax__cont">
<div id="contents">
<section id="section1" 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>
<!-- section -->
<section id="section2" class="content__item">
<span class="content__item__num">02</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>
<!-- section2 -->
<section id="section3" class="content__item">
<span class="content__item__num">03</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>
<!-- section3 -->
<section id="section4" class="content__item">
<span class="content__item__num">04</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">1퍼센트의 가능성, 그것이 나의 길이다. </p>
</section>
<!-- section4 -->
<section id="section5" class="content__item">
<span class="content__item__num">05</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>
<!-- section5 -->
<section id="section6" class="content__item">
<span class="content__item__num">06</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>
<!-- section6 -->
<section id="section7" class="content__item">
<span class="content__item__num">07</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>
<!-- section7 -->
<section id="section8" class="content__item">
<span class="content__item__num">08</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>
<!-- section8 -->
</div>
</main>
<!-- //main -->
<aside id="parallax__info">
<div class="scroll">scrollTop : <span>0</span>px</div>
<div class="infoTop">
<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>
<!-- parallax__info -->
728x90
'Effect > 퍼럴랙스' 카테고리의 다른 글
패럴렉스 이펙트 06 (2) | 2022.10.07 |
---|---|
퍼럴랙스 이펙트 05 (2) | 2022.09.20 |
퍼럴랙스 이펙트 03 (3) | 2022.09.12 |
퍼럴랙스 이펙트 02 (2) | 2022.09.12 |
퍼럴랙스 이펙트 01 (6) | 2022.09.06 |
댓글