Skip to content

Instantly share code, notes, and snippets.

@oilsinwater
Created May 24, 2018 23:56
Show Gist options
  • Save oilsinwater/9f82bd431f05f4aa2ec4be58d0fdd12b to your computer and use it in GitHub Desktop.
Save oilsinwater/9f82bd431f05f4aa2ec4be58d0fdd12b to your computer and use it in GitHub Desktop.
Off-Canvas Hamburger menu
// Here's the JavaScript used to toggle the open class:
menu.addEventListener('click', function(e) {
drawer.classList.toggle('open');
e.stopPropagation();
});
// Here's the relevant CSS for transitioning the hamburger menu:
nav {
width: 300px;
position: absolute;
/* This trasform moves the drawer off canvas. */
-webkit-transform: translate(-300px, 0);
transform: translate(-300px, 0);
/* Optionally, we animate the drawer. */
transition: transform 0.3s ease;
}
nav.open {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment