Fullscreen Hamburger Navigation Interactions

Fullscreen Hamburger Navigation Interactions
File Size: 5.37 KB
Views Total: 459
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A mobile-first navigation system written in jQuery and CSS/CSS3 that morphs a hamburger toggle button into a fullscreen navigation menu when triggered.

See It In Action:

See the Pen Hamburger Menu Interaction by Tsukasa Aoki (@TKS31) on CodePen.

How to use it:

1. Create a fullscreen navigation menu for your web app.

<nav class="nav js-nav">
  <ul class="nav__list js-nav__list">
    <li class="nav__item">
      <a href="#" class="nav__link">Home</a>
    </li>
    <li class="nav__item">
      <a href="#" class="nav__link">About</a>
    </li>
    <li class="nav__item">
      <a href="#" class="nav__link">Contact</a>
    </li>
  </ul>
</nav>

2. The necessary CSS styles for the fullscreen navigation menu.

.nav {
  display: block;
  position: absolute;
  bottom: 16px;
  right: 16px;
  background-color: #222;
  height: 50px;
  width: 50px;
  border-radius: 50%;
  z-index: 10;
  transition-duration: .4s;
}

.nav.open {
  background-color: rgba(0, 0, 0, 0.9);
  width: 320px;
  height: 480px;
  position: absolute;
  right: 0px;
  bottom: 0px;
  border-radius: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.nav__list {
  display: none;
}

.nav__list.show {
  display: flex;
  flex-direction: column;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav__item {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  width: 100%;
  opacity: 0;
  animation-name: fadein;
  animation-duration: 1s;
  animation-fill-mode: forwards;
}

.nav__item:nth-child(1) {
  animation-delay: .2s;
}

.nav__item:nth-child(2) {
  animation-delay: .3s;
}

.nav__item:nth-child(3) {
  animation-delay: .4s;
}

.nav__item:nth-child(4) {
  animation-delay: .5s;
}

.nav__item:not(:last-child) {
  margin-bottom: 32px;
}

.nav__link {
  font-size: 24px;
  letter-spacing: 0.1em;
  text-decoration: none;
  color: #fff;
}

@keyframes fadein {
  0% {
    opacity: 0;
    transform: translateY(24px);
  }
  100% {
    opacity: 1;
  }
}

3. Create a hamburger button to toggle the fullscreen navigation menu.

<div class="menu js-menu">
  <span class="menu__line"></span>
  <span class="menu__line"></span>
  <span class="menu__line"></span>
</div>
.menu {
  display: block;
  position: absolute;
  bottom: 16px;
  right: 16px;
  background-color: #222;
  height: 50px;
  width: 50px;
  border-radius: 50%;
  z-index: 20;
  box-shadow: 0px 3px 8px #333;
  cursor: pointer;
}

.menu__line {
  display: block;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 4px;
  background-color: #fff;
  border-radius: 13px;
  transition-duration: .4s;
}

.menu__line:nth-child(1) {
  top: 14px;
}

.menu__line:nth-child(2) {
  top: 23px;
}

.menu__line:nth-child(3) {
  bottom: 14px;
}

.menu.active {
  background-color: rgba(0, 0, 0, 0);
  box-shadow: none;
}

.menu.active .menu__line:nth-child(1) {
  transform: translate(-12px, 9px) rotate(-45deg);
}

.menu.active .menu__line:nth-child(2) {
  transition-duration: 0s;
  opacity: 0;
}

.menu.active .menu__line:nth-child(3) {
  transform: translate(-12px, -9px) rotate(45deg);
}

4. Load the necessary jQuery JavaScript library in the document.

<script src="/path/to/cdn/jquery.slim.min.js"></script>

5. The main JavaScript (jquery script) to enable thhe morphing effect.

$('.js-menu').on('click', () => {
  $('.js-menu').toggleClass('active');
  $('.js-nav').toggleClass('open');
  $('.js-nav__list').toggleClass('show');
});

This awesome jQuery plugin is developed by TKS31. For more Advanced Usages, please check the demo page or visit the official website.