코드랩 레퍼런스

Parallax - Dot Menu 본문

SAMPLE

Parallax - Dot Menu

webstoryboy 2018. 1. 25. 14:03

See the Pen Parallax = Dot Menu by Webstoryboy (@webstoryboy) on CodePen.

<!DOCTYPE html>
<html lang="ko">
<head>
	<meta charset="UTF-8">
	<title>Parallax Dot Nav</title>
	<style>
		@import url('https://fonts.googleapis.com/css?family=Playball');
		/* font-family: 'Playball', cursive; */
		* {padding: 0; margin:0;}
		li {list-style: none;}

		/* dot */
		#dot {position: fixed; right:20px; top: 50%; transform: translatey(-50%);}
		#dot li a {position: relative; width: 15px; height: 15px; border-radius:50%; margin:8px; background-color:rgba(255,255,255,0.5); display: block;}
		#dot li a em {opacity:0; position: absolute; right: 37px; top:-7px; background: rgba(0,0,0,0.55); color:#fff; padding: 8px 14px 5px 14px; display:block; transition: all 0.3s ease; opacity:0;}
		#dot li a em:after {content:''; position: absolute; right:-5px; top:9px;
		    border-left: 5px solid rgba(0,0,0,0.55); 
		    border-top: 5px solid transparent;
		    border-bottom: 5px solid transparent;
		}
		#dot li.active a {background-color:rgba(255,255,255,1); position: relative;}
		#dot li.active a em {opacity: 1; right: 27px; opacity:1; }

		/* contents */
		#contents {font-size: 40px; color:#fff; text-align: center; font-family: 'Playball', cursive;}
		#contents > div {height: 100vh; line-height: 100vh;}

		/* section */
		#section1 {background-image: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);}
		#section2 {background-image: linear-gradient(to top, #c471f5 0%, #fa71cd 100%);}
		#section3 {background-image: linear-gradient(120deg, #f6d365 0%, #fda085 100%);}
		#section4 {background-image: linear-gradient(120deg, #d4fc79 0%, #96e6a1 100%);}
		#section5 {background-image: linear-gradient(120deg, #a6c0fe 0%, #f68084 100%);}
		#section6 {background-image: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%);}
	</style>
</head>
<body>
	<nav id="dot">
		<ul>
			<li class="active"><a href="#"><em>Intro</em></a></li>
			<li><a href="#"><em>Skill</em></a></li>
			<li><a href="#"><em>Website</em></a></li>
			<li><a href="#"><em>Work</em></a></li>
			<li><a href="#"><em>About</em></a></li>
			<li><a href="#"><em>Contact</em></a></li>
		</ul>
	</nav>

	<section id="contents">
		<div id="section1">
			<div class="container">
				<div class="sec1">
					<h2>Think Different</h2>
				</div>
			</div>
		</div>
		<div id="section2">
			<div class="container">
				<div class="sec2">
					<h2>Raise Your Head</h2>
				</div>
			</div>
		</div>
		<div id="section3">
			<div class="container">
				<div class="sec3">
					<h2>The Life is only once</h2>
				</div>
			</div>
		</div>
		<div id="section4">
			<div class="container">
				<div class="sec4">
					<h2>I must do what I want to do</h2>
				</div>
			</div>
		</div>
		<div id="section5">
			<div class="container">
				<div class="sec5">
					<h2>Time is Life itself</h2>
				</div>
			</div>
		</div>
		<div id="section6">
			<div class="container">
				<div class="sec6">
					<h2>There is no destiny</h2>
				</div>
			</div>
		</div>
	</section>
	
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
	<script>
		var nav = $("#dot ul li");
		var contents = $("#contents > div");

		nav.click(function(e){
			e.preventDefault();
			var target = $(this);
			var index = target.index();
			var section = contents.eq(index);
			var offset = section.offset().top;

			$("html,body").animate({scrollTop:offset},600,"easeInOutExpo");
		});


		$(window).scroll(function(){
			var wScroll = $(this).scrollTop();

			if(wScroll >= contents.eq(0).offset().top){
				nav.removeClass("active");
				nav.eq(0).addClass("active");
			}
			if(wScroll >= contents.eq(1).offset().top){
				nav.removeClass("active");
				nav.eq(1).addClass("active");
			}
			if(wScroll >= contents.eq(2).offset().top){
				nav.removeClass("active");
				nav.eq(2).addClass("active");
			}
			if(wScroll >= contents.eq(3).offset().top){
				nav.removeClass("active");
				nav.eq(3).addClass("active");
			}
			if(wScroll >= contents.eq(4).offset().top){
				nav.removeClass("active");
				nav.eq(4).addClass("active");
			}
			if(wScroll >= contents.eq(5).offset().top){
				nav.removeClass("active");
				nav.eq(5).addClass("active");
			}
		});
	</script>
</body>
</html>

Share

Ad

Comments