Created
May 24, 2018 23:56
-
-
Save oilsinwater/9f82bd431f05f4aa2ec4be58d0fdd12b to your computer and use it in GitHub Desktop.
Off-Canvas Hamburger menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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