728x90
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parallax Layout</title>
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@100&display=swap" rel="stylesheet">
<style>
@font-face {
font-family: 'NEXONLv1Gothic';
font-weight: 300;
src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_20-04@2.1/NEXON Lv1 Gothic OTF Light.woff') format('woff');
font-style: normal;
}
@font-face {
font-family: 'NEXONLv1Gothic';
font-weight: 400;
src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_20-04@2.1/NEXON Lv1 Gothic OTF.woff') format('woff');
font-style: normal;
}
* {
margin: 0; padding: 0;
}
/* layout */
.parallax {
background: #222;
color:#fff;
font-family: NEXONLv1Gothic;
font-weight: 300;
}
#paraHeader {
padding: 20px;
}
#paraHeader h1 {
display: inline-block;
font-size: 20px;
border-bottom: 1px dashed #fff;
margin-bottom: 8px;
}
#paraCont {
max-width: 1600px;
margin: 0 auto;
width: 100%;
overflow: hidden;
}
#paraFooter {
padding: 10vw 0;
}
#paraFooter h2 {
font-size: 8vw;
line-height: 1.2;
padding: 10vw 8vw 0 8vw;
text-transform: uppercase;
margin-bottom: 3vw;
}
#paraFooter h2 em {
display: block;
font-family: 'lato';
font-weight: 100;
padding-left: 18vw;
}
#paraFooter .footerinfo {
padding: 20px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
background: #000;
padding: 15px 20px;
margin-bottom: 2px;
}
#paraFooter .footerinfo h3 {
padding: 0 10px;
}
#paraFooter .footerinfo li {
display: inline;
list-style: none;
}
#paraFooter .footerinfo li a {
text-decoration: none;
color: #fff;
border: 1px dashed #fff;
width: 30px; height: 30px;
border-radius: 50%;
line-height: 2;
display: inline-block;
}
#paraFooter .footerinfo li.active a,
#paraFooter .footerinfo li a:hover {
background: #fff;
color:#000;
}
/* content_item */
.content_item {
width: 1000px;
max-width: 70vw;
margin: 30vw 0;
text-align: right;
position: relative;
padding-top: 10vw;
}
.content_item:nth-child(even) {
margin-left: auto;
text-align: left;
}
.content_item_num {
font-family: Lato;
font-size: 25vw;
opacity: 0.07;
position: absolute;
right: -5vw;top: -10vw;
}
.content_item:nth-child(even) .content_item_num {
right: auto;
left: -5vw;
}
.content_item_title {
padding-bottom: 1vw;
font-size: 2vw;
}
.content_item_imgWrap {
width: 100%;
padding-bottom: 56%;
background: #000;
position: relative;
}
.content_item_img {
position: absolute;
left: 0; top:0;
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-size: cover;
filter: saturate(0%);
transition: all 1s;
}
.content_item_img:hover {
filter: saturate(100%);
}
.content_item_desc {
font-size: 4vw;
line-height: 1.4;
word-break: keep-all;
margin-top: -6vw;
margin-right: -3vw;
position: relative;
z-index: 100;
}
.content_item:nth-child(even) .content_item_desc {
margin-right: 0;
margin-left: -3vw;
}
.content_item:nth-child(1) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg1.jpg);
}
.content_item:nth-child(2) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg2.jpg);
}
.content_item:nth-child(3) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg3.jpg);
}
.content_item:nth-child(4) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg4.jpg);
}
.content_item:nth-child(5) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg5.jpg);
}
.content_item:nth-child(6) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg6.jpg);
}
.content_item:nth-child(7) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg7.jpg);
}
.content_item:nth-child(8) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg8.jpg);
}
.content_item:nth-child(9) .content_item_img {
background-image: url(https://webstoryboy.github.io/wtss/refer-effect/assets/img/bg9.jpg);
}
/* nav */
.paraNav {
position: fixed;
right: 20px; top: 20px;
z-index: 1000;
background: rgba(0,0,0,.4);
padding: 15px 20px;
border-radius: 50px;
}
.paraNav li {
display: inline-block;
list-style: none;
}
.paraNav li a {
color: #fff;
text-decoration: none;
display: inline-block;
padding: 5px;
width: 30px; height: 30px;
text-align: center;
line-height: 30px;
}
.paraNav li.active a {
background: #fff;
color: #000;
border-radius: 50%;
}
/* info */
.paraScroll {
position: fixed;
left: 20px;
bottom: 20px;
z-index: 1000;
background: rgba(0,0,0,.4);
color: #fff;
height: 40px;
line-height: 40px;
border-radius: 50px;
text-align: center;
font-size: 12px;
padding: 0px 20px;
}
.paraInfo {
position: fixed;
left: 20px;
bottom: 70px;
z-index: 1000;
background: rgba(0,0,0,.4);
color: #fff;
padding: 20px;
font-size: 12px;
line-height: 1.8;
border-radius: 10px;
}
.paraInfo li {
list-style: none;
}
</style>
</head>
<body class="parallax">
<!-- info -->
<div class="paraScroll">scrollTop() : <span>0</span>px</div>
<div class="paraInfo">
<ul>
<li>#section1 offset() : <span class="offset1">0</span></li>
<li>#section2 offset() : <span class="offset2">0</span></li>
<li>#section3 offset() : <span class="offset3">0</span></li>
<li>#section4 offset() : <span class="offset4">0</span></li>
<li>#section5 offset() : <span class="offset5">0</span></li>
<li>#section6 offset() : <span class="offset6">0</span></li>
<li>#section7 offset() : <span class="offset7">0</span></li>
<li>#section8 offset() : <span class="offset8">0</span></li>
<li>#section9 offset() : <span class="offset9">0</span></li>
</ul>
</div>
<!-- //info -->
<header id="paraHeader">
<h1>Parallax Effect - JQuery</h1>
<p>패럴랙스 스크롤링 효과 - 메뉴이동</p>
</header>
<!-- //header -->
<nav class="paraNav">
<ul>
<li class="active"><a href="#section1">s1</a></li>
<li><a href="#section2">s2</a></li>
<li><a href="#section3">s3</a></li>
<li><a href="#section4">s4</a></li>
<li><a href="#section5">s5</a></li>
<li><a href="#section6">s6</a></li>
<li><a href="#section7">s7</a></li>
<li><a href="#section8">s8</a></li>
<li><a href="#section9">s9</a></li>
</ul>
</nav>
<!-- //nav -->
<main id="paraCont">
<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>
<!-- //section1 -->
<section id="section2" class="content_item">
<span class="content_item_num">02</span>
<h2 class="content_item_title">Section2</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">Section3</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">Section4</h2>
<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>
<h2 class="content_item_title">Section5</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">Section6</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">Section7</h2>
<figure class="content_item_imgWrap">
<div class="content_item_img"></div>
</figure>
<p class="content_item_desc">단 1분이라도 버티기 힘들다고 생각할때 당장 포기하고 싶은 마음이 들때가 당신의 수준이 달라지는 정말 중요한 순간이다.</p>
</section>
<!-- //section7 -->
<section id="section8" class="content_item">
<span class="content_item_num">08</span>
<h2 class="content_item_title">Section8</h2>
<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>
<h2 class="content_item_title">Section9</h2>
<figure class="content_item_imgWrap">
<div class="content_item_img"></div>
</figure>
<p class="content_item_desc">작은 변화를 만들어 낼 때 진짜 삶이 시작된다.</p>
</section>
<!-- //section9 -->
</main>
<!-- //main-->
<footer id="paraFooter">
<h2>Parallax <em>Scrolling</em></h2>
<div class="footerinfo">
<h3>제이쿼리</h3>
<ul>
<li class="active"><a href="parallaxEffect01-jquery.html">1</a></li>
<li><a href="parallaxEffect02-jquery.html">2</a></li>
<li><a href="parallaxEffect03-jquery.html">3</a></li>
<li><a href="parallaxEffect04-jquery.html">4</a></li>
<li><a href="parallaxEffect05-jquery.html">5</a></li>
<li><a href="parallaxEffect06-jquery.html">6</a></li>
<li><a href="parallaxEffect07-jquery.html">7</a></li>
<li><a href="parallaxEffect08-jquery.html">8</a></li>
</ul>
</div>
<div class="footerinfo">
<h3>자바스크립트</h3>
<ul>
<li><a href="parallaxEffect01-javascript.html">1</a></li>
<li><a href="parallaxEffect02-javascript.html">2</a></li>
<li><a href="parallaxEffect03-javascript.html">3</a></li>
<li><a href="parallaxEffect04-javascript.html">4</a></li>
<li><a href="parallaxEffect05-javascript.html">5</a></li>
<li><a href="parallaxEffect06-javascript.html">6</a></li>
<li><a href="parallaxEffect07-javascript.html">7</a></li>
<li><a href="parallaxEffect08-javascript.html">8</a></li>
</ul>
</div>
</footer>
<!-- script -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
// 메뉴버튼 클릭 후 이동하기
$(".paraNav ul li").click(function(e){
e.preventDefault(); //#의 기본 기능을 차단
let target = $(this); //사용자가 클릭한 버튼의 타겟이 저장
let index = target.index(); //인덱스(번호)를 부여해서 저장
let section = $(".content_item").eq(index); // eq() : 인덱스 순서대로 선택할수 있도록 해준다.
let offset = section.offset().top; //offset() : 요소의 위치(문서)
$("html, body").animate({scrollTop:offset}, 600); //offset 값을 scrollTop 값에 대입 시켜줄때 애니매이션 효과를 넣어준것.
});
// 스크롤이 됬을때,
$(window).scroll(function(){
let scrollTop = $(window).scrollTop(); // scrollTop() : 브라우저의 위치값을 알려주는 메소드
if(scrollTop >= $("#section1").offset().top -2){
$(".paraNav ul li").eq(0).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section2").offset().top -2){
$(".paraNav ul li").eq(1).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section3").offset().top -2){
$(".paraNav ul li").eq(2).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section4").offset().top -2){
$(".paraNav ul li").eq(3).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section5").offset().top -2){
$(".paraNav ul li").eq(4).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section6").offset().top -2){
$(".paraNav ul li").eq(5).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section7").offset().top -2){
$(".paraNav ul li").eq(6).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section8").offset().top -2){
$(".paraNav ul li").eq(7).addClass("active").siblings().removeClass("active");
}
if(scrollTop >= $("#section9").offset().top -2){
$(".paraNav ul li").eq(8).addClass("active").siblings().removeClass("active");
}
//info (위치값 정보표시)
$(".paraScroll span").text(parseInt(scrollTop)); //브라우저의 스크롤 값을 텍스트로 표시 parseInt() : 문자열 정수로 변경
$(".offset1").text(parseInt($("#section1").offset().top) + "px");
$(".offset2").text(parseInt($("#section2").offset().top) + "px");
$(".offset3").text(parseInt($("#section3").offset().top) + "px");
$(".offset4").text(parseInt($("#section4").offset().top) + "px");
$(".offset5").text(parseInt($("#section5").offset().top) + "px");
$(".offset6").text(parseInt($("#section6").offset().top) + "px");
$(".offset7").text(parseInt($("#section7").offset().top) + "px");
$(".offset8").text(parseInt($("#section8").offset().top) + "px");
$(".offset9").text(parseInt($("#section9").offset().top) + "px");
});
</script>
</body>
</html>
'내마음대로만들어보자 > JS' 카테고리의 다른 글
Parallax Effect - JavaScript (숨김메뉴) (0) | 2022.01.24 |
---|---|
Parallax Effect - JavaScript (메뉴이동1) (0) | 2022.01.10 |
Parallax Effect - Layout (0) | 2022.01.03 |
복합 객체(=합성 객체) (0) | 2021.10.10 |
원시값(=단순값) (0) | 2021.10.05 |