Swipeable Hamburger Menu Concept with Vanilla JS

Swipeable hamburger menu concept with vanilla JS that allows users to toggle menu using scroll events in mobile view.

javascript swipe side menu, mobile web swipe gesture, swipe menu javascript, mobile web bottom navigation css, swipeable menu css, swipe scroll javascript

How to make use of it:

1. Create an off-canvas menu on the page.

<div id="hamburger-menu">
  <ul class="list">
    <li class="active"><a>Home</a></li>
    <li><a>About</a></li>
    <li><a>Contact</a></li>
  </ul>
</div>

2. Create a background overlay that appears when toggling off the panel.

<div id="hamburger-menu__bg"></div>

3. Create a hamburger toggle button to toggle navigation off the canvas.

<div id="hamburger-btn">
  <span></span>
  <span></span>
  <span></span>
</div>

4. Basic CSS/CSS3 Styles.

.hamburger-drawer, #invis-drawer, #hamburger-menu, #hamburger-menu__bg {
  position: fixed;
  min-height: 100vh
}
#invis-drawer {
  width: 5%;
  background-color: #444
}
#hamburger-menu {
  width: 60%;
  background-color: #f1f1f1;
  z-index: 100;
  transform: translate3d(-100%, 0, 0)
}
#hamburger-menu::after {
  content: '';
  position: fixed;
  top: 0;
  right: -20px;
  width: 20px;
  min-height: 100vh
}
#hamburger-menu ul.list {
  list-style: none;
  padding: 0
}
#hamburger-menu ul.list li { padding: 15px }
#hamburger-menu ul.list li.active { background-color: rgba(0, 0, 0, 0.1) }
#hamburger-menu__bg {
  z-index: -1;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.5)
}
#hamburger-btn {
  position: relative;
  height: 22px;
  margin-left: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-around
}
#hamburger-btn span {
  width: 30px;
  height: 2px;
  background-color: #000
}

5. Main JavaScript to activate off-board navigation.

var hamburgerDrawer = document.getElementById('hamburger-menu');
var hamburgerBtn = document.getElementById('hamburger-btn');
var hamburgerDrawerBg = document.getElementById('hamburger-menu__bg');
var axisCords;
var hamburgerDrawerWidth = hamburgerDrawer.clientWidth;
var oneByForthScreen = window.innerWidth / 4;
var openStatus = false;
function drawToStart() {
  hamburgerDrawer.animate([
    {
      transform: `translate3d(${axisCords ? axisCords + 'px' : 0 + 'px'}, 0, 0)`
    },
    {
      transform: 'translate3d(-100%, 0, 0)'
    }
  ], {
      duration: 500,
      easing: 'ease-in-out'
    });
  hamburgerDrawer.style.transform = 'translate3d(-100%, 0, 0)';
  openStatus = false;
}
function drawToEnd() {
  hamburgerDrawer.animate([
    {
      transform: `translate3d(${axisCords ? axisCords + 'px' : -100 + '%'}, 0, 0)`
    },
    {
      transform: 'translate3d(0, 0, 0)'
    }
  ], {
      duration: 500,
      easing: 'ease-in-out'
    });
  hamburgerDrawer.style.transform = 'translate3d(0, 0, 0)';
  openStatus = true;
}
// Click on Menu Button to Drawer
hamburgerBtn.addEventListener('click', drawToEnd);
// Click on Background to Close
hamburgerDrawerBg.addEventListener('click', function(){
  if (openStatus) drawToStart();
});
hamburgerDrawer.addEventListener('touchmove',
  function(e) {
    axisCords = e.changedTouches[0].pageX - hamburgerDrawerWidth;
    if (axisCords > 0) axisCords = 0;
    this.style.transform = 'translate3d(' + axisCords + 'px, 0, 0)';
});
hamburgerDrawer.addEventListener('touchend',
  function(e) {
    var endPoint = e.changedTouches[0].pageX;
    var isOverThreshold = endPoint > oneByForthScreen && endPoint < hamburgerDrawerWidth;
    if (endPoint < oneByForthScreen) {
      drawToStart();
    } else if (isOverThreshold) {
      drawToEnd();
    } else {
      openStatus = true;
    }
    axisCords = null;
  });

swipeable off-canvas navigation, swipeable-hamburger Plugin/Github


See Demo And Download

Official Website(kaungmyatlwin): Click Here

This superior jQuery/javascript plugin is developed by kaungmyatlwin. For extra advanced usage, please go to the official website.

Related Posts

Searchable-Select-Dropdown

A Simple Searchable Select Dropdown Plugin | jQuery Select Search

Simple jQuery search on the selection options plugin for your website. Next, there is a checkbox replacement plugin that refines and beautifies the original selection element with…

country-dropdown-with-flags

A Quick jQuery-Based Country Picker With Flags | Country Select JS

Country Select JS is a jQuery plugin to select a country, based on the international phone input plugin. Adds a flag dropdown to any input, which lists…

Autocomplete-and-Typeahead-Javascript-Library

Simple and Fast Autocomplete and Typeahead Javascript Library | autoComplete.js

autoComplete.js is a simple, pure, and incrementally designed JavaScript library for speed, high versatility, and seamless integration with a wide variety of projects and systems. Features Pure…

Bootstrap-Notification-Message-Alert-Plugin

Bootstrap Notification Message Alert Plugin with jQuery

BootstrapMsg is a jQuery plugin for displaying messages with Bootstrap alert classes to generate hierarchical in-page navigation for an extended webpage sectioned by heading components. Using Bootstrap…

jquery-google-chart-plugin

jQuery Plugin for Transforming HTML Tables Into Charts Using Google Charts

Chartinator is a jQuery plugin for converting HTML tables, Google Sheets and js arrays into charts using Google Charts. Use data from HTML tables Chartinator is designed…

free-vue-chart-library

Customizable & Composable Charts for VueJS | vue-wcharts

WCharts is a library that makes it easy to create your own charts using Vuejs. You can easily create reusable chart components. Use a basic layout or…