Skip to content

Instantly share code, notes, and snippets.

@trooperandz
Created November 18, 2018 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trooperandz/4e66ad4460505a7aa846ec57186de839 to your computer and use it in GitHub Desktop.
Save trooperandz/4e66ad4460505a7aa846ec57186de839 to your computer and use it in GitHub Desktop.
CSS Grid Dashboard Sliding Side Nav JavaScript
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
const menuIconEl = $('.menu-icon');
const sidenavEl = $('.sidenav');
const sidenavCloseEl = $('.sidenav__close-icon');
// Add and remove provided class names
function toggleClassName(el, className) {
if (el.hasClass(className)) {
el.removeClass(className);
} else {
el.addClass(className);
}
}
// Open the side nav on click
menuIconEl.on('click', function() {
toggleClassName(sidenavEl, 'active');
});
// Close the side nav on click
sidenavCloseEl.on('click', function() {
toggleClassName(sidenavEl, 'active');
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment