Morphing Fullscreen Nav For One Page Scrolling Website
File Size: | 6.78 KB |
---|---|
Views Total: | 972 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |
A jQuery/CSS powered navigation system that morphs a hamburger button into a fullscreen navigation containing anchor links generated from content sections within the document.
Great for one page scrolling website that offers a better navigation experience when switching between fullscreen page sections.
How to use it:
1. Load the latest Font Awesome Iconic Font for the necessary icon.
<link rel="stylesheet" href="/path/to/font-awesome/all.min.css" />
2. Create a onboard screen for the one page scrolling website.
<header> <div class="triangle left"><h1>This is a title</h1></div> <div class="triangle right"><h1>This is a title</h1></div> <button></button> </header>
3. Create the HTML for the fullscreen navigation & page sections.
<nav> <ul> <li>Section 1</li> <li>Section 2</li> <li>Section 3</li> </ul> <div id="nav-close"><i class="fas fa-times"></i></div> </nav>
<content> <section>Section 1</section> <section>Section 2</section> <section>Section 3</section> </content>
4. The necessary CSS styles.
* { margin: 0; padding: 0; box-sizing: border-box; } body { min-height: 300vh; background-image: linear-gradient(to top, #09203f 0%, #537895 100%); } header { position: fixed; width: 100%; height: 100%; top: 0; left: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; } header h1, header button { position: relative; z-index: 10; } header h1 { text-transform: uppercase; letter-spacing: 1pt; font-size: 3em; color: #fff; } header button { font-family: "Font Awesome 5 Free"; font-weight: 900; position: absolute; bottom: 100px; left: calc(50% - 60px); width: 120px; height: 50px; border: 0; box-shadow: 2px 1px 20px 0 rgba(0, 0, 0, 0.5); border-radius: 10px; cursor: pointer; background: #fff; font-size: 1em; color: #09203f; transition: all 0.8s cubic-bezier(0.645, 0.045, 0.355, 1), transform 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955), box-shadow 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955); overflow: hidden; } header button:hover { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.5); } header button:focus { outline: 0; } header button:before, header button:after { font-family: "Font Awesome 5 Free"; transition: all 0.8s cubic-bezier(0.645, 0.045, 0.355, 1); top: 17px; position: absolute; } header button:before { content: ""; opacity: 1; left: 53px; } header button:after { content: ""; opacity: 0; left: 0; } header .triangle { position: absolute; z-index: 1; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(to top, #09203f 0%, #537895 100%); transition: all 0.8s cubic-bezier(0.645, 0.045, 0.355, 1); display: flex; justify-content: center; align-items: center; pointer-events: none; } header .triangle.left { clip-path: polygon(0 0, 0% 100%, 100% 100%); } header .triangle.right { clip-path: polygon(100% 0, 0 0, 100% 100%); } header.open .triangle.left { clip-path: polygon(0 0, 0 100%, 0 100%); } header.open .triangle.right { clip-path: polygon(100% 0, 100% 0, 100% 100%); } header.open button { left: 40px; bottom: 40px; width: 50px; border-radius: 50%; } header.open button:before { opacity: 0; left: 100%; } header.open button:after { opacity: 1; left: 18px; } header.open button.menu { width: 100%; height: 100%; bottom: 0; left: 0; border-radius: 0; } header.open button.menu:after { left: -100%; } content section { height: 100vh; display: flex; justify-content: center; align-items: center; font-weight: 700; text-transform: uppercase; font-size: 1em; letter-spacing: 2pt; color: #fff; } nav { position: fixed; width: 100%; height: 100%; top: 0; left: 0; display: flex; justify-content: center; align-items: center; display: none; } nav ul { list-style: none; } nav ul li { font-weight: 700; text-transform: uppercase; line-height: 2; letter-spacing: 1pt; font-size: 2em; color: #09203f; animation: fadeDown 0.5s forwards; opacity: 0; cursor: pointer; transform: translateY(-20px); transition: all 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955); } nav ul li:hover { text-shadow: 2px 1px 40px rgba(0, 0, 0, 0.5); opacity: 0.8; } nav ul li:nth-child(1) { animation-delay: 0.8s; } nav ul li:nth-child(2) { animation-delay: 0.9s; } nav ul li:nth-child(3) { animation-delay: 1s; } nav #nav-close { position: fixed; top: 40px; right: 40px; font-size: 1.5em; cursor: pointer; animation: fadeDown 0.5s forwards; animation-delay: 1.1s; opacity: 0; color: #09203f; transform: translateY(-20px); } @keyframes fadeDown { 0% { opacity: 0; transform: translateY(-20px); } 100% { opacity: 1; transform: translateY(0); } }
5. Load the latest jQuery library right before the </body>
tag.
<script src="/path/to/cdn/jquery.min.js"></script>
6. Activate the fullscreen navigation.
// function to open/close nav function toggleNav(){ // if nav is open, close it if($("nav").is(":visible")){ $("nav").fadeOut(); $("button").removeClass("menu"); } // if nav is closed, open it else{ $("button").addClass("menu"); $("nav").fadeIn().css('display', 'flex'); } } // when clicking + button $("button").click(function(){ // when clicking ☰ button, open nav if($("header").hasClass("open")){ toggleNav(); } // when clicking + button, open header else{ $("header").addClass("open"); } }); // close nav $("#nav-close").click(function(){ toggleNav(); }); // scroll to sections $("nav li").click(function(){ // get index of clicked li and select according section var index = $(this).index(); var target = $("content section").eq(index); toggleNav(); $('html,body').delay(300).animate({ scrollTop: target.offset().top }, 500); });
This awesome jQuery plugin is developed by tobiasglaus. For more Advanced Usages, please check the demo page or visit the official website.