Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main class="demo">
  <section class="demo-left">
    <p>A simple mobile menu that is easy to integrate into a new or existing project. Clear Menu is actually two separate components acting as one; a panel that is revealed into the viewport, and a mobile menu.</p>

    <p>This is a developer focused plug-in. It is not meant to solve all navigation patterns but instead provide a base for you to build upon. The <code>.scss</code> is just enough to make all the components work properly, but it is expected that you will
      hack it to fit the design of your specific project.</p>

    <h3>Example Usage:</h3>

    <pre>
    $(function() {
      $('#panel').clearmenu();
    });
    </pre>

    <p>View <a href="https://github.com/bebaps/clear-menu">the repo</a> for full documentation and options.</p>
  </section>

  <section class="demo-right">
    <header class="demo-header">
      <button class="cm-button">
        <span class="cm-button_text">Menu</span>
        <span class="cm-button_icon"></span>
      </button>
    </header>

    <nav id="panel" class="cm-panel">
      <ul class="cm-menu">
        <li>
          <a href="#">Link</a>
          <ul>
            <li><a href="#">Sub Link</a></li>
            <li><a href="#">Sub Link</a></li>
            <li><a href="#">Sub Link</a></li>
          </ul>
        </li>
        <li><a href="#">Link</a></li>
        <li>
          <a href="#">Link</a>
          <ul>
            <li><a href="#">Sub Link</a></li>
            <li><a href="#">Sub Link</a></li>
            <li><a href="#">Sub Link</a></li>
          </ul>
        </li>
        <li><a href="#">Link</a></li>
      </ul>
    </nav>
  </section>
</main>
              
            
!

CSS

              
                // Colors
// -----------------------------------------------------------------------------
$cm_color-primary: #000 !default;
// Panel Settings
// -----------------------------------------------------------------------------
$cm_panel-position: absolute !default;
$cm_panel-top: 0 !default;
$cm_panel-width: 100% !default;
$cm_panel-height: 100% !default;
$cm_panel-transition: ease-in-out !default;
$cm_panel-speed: 0.25s !default;
// Menu Settings
// -----------------------------------------------------------------------------
$cm_list-item-height: 30px !default;
// Panel
// -----------------------------------------------------------------------------
.cm-panel,
.cm-panel * {
  box-sizing: border-box;
}

.cm-panel {
  display: block;
  position: $cm_panel-position;
  top: $cm_panel-top;
  left: 0;
  z-index: 99;
  padding: 20px;
  width: $cm_panel-width;
  max-width: 100%;
  height: $cm_panel-height;
  max-height: 100%;
  background-color: #fff;
  overflow: auto;
  visibility: hidden;
  transition: all $cm_panel-speed $cm_panel-transition;
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-overflow-scrolling: touch;
  // For when the panel is visible
  &.cm-open {
    visibility: visible;
    transform: translateY(0);
    opacity: 1;
  }
}

// Panel Reveals
// -----------------------------------------------------------------------------
// Reveal from the top
.cm-top {
  transform: translateY(-100%);
}

// Reveal from the bottom
.cm-bottom {
  transform: translateY(100%);
  top: unset;
  bottom: 0;
}

// Reveal from the left
.cm-left {
  transform: translateX(-100%);
}

// Reveal from the right
.cm-right {
  transform: translateX(100%);
  left: unset;
  right: 0;
}

// Fade in
.cm-fade {
  opacity: 0;
}

// Menu
// -----------------------------------------------------------------------------
.cm-menu {
  display: block;
  position: relative;
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 0;
  list-style: none;
  li {
    position: relative;
    min-height: $cm_list-item-height;
    > ul {
      display: none;
      position: relative;
      margin-top: 0;
      margin-bottom: 0;
      padding-left: 0;
      a {
        position: relative;
        padding: 5px 15px;
      }
    }
  }
  a {
    display: block;
    position: relative;
    padding-top: 6px;
    padding-bottom: 6px;
    min-height: $cm_list-item-height;
    background-color: transparent;
    overflow: hidden;
    text-decoration: none;
    -webkit-text-decoration-skip: objects;
  }
}

// Button
// -----------------------------------------------------------------------------
.cm-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  outline: 1px solid rgba($cm_color-primary, 0.1);
  margin: 0;
  padding: 14px 16px;
  color: initial;
  text-decoration: none;
  text-transform: none;
  font: inherit;
  overflow: visible;
  -webkit-text-decoration-skip: objects;
  -webkit-tap-highlight-color: transparent;
  &:active,
  &:focus,
  &:hover {
    outline: 1px solid rgba($cm_color-primary, 0.3);
  }
}

// Button text
.cm-button_text {
  display: inline-block;
}

// Hamburger icon
.cm-button_icon {
  display: inline-block;
  position: relative;
  width: 18px;
  height: 2px;
  background-color: $cm_color-primary;
  transition: background-color $cm_panel-speed $cm_panel-transition;
  &::before,
  &::after {
    content: "";
    position: absolute;
    right: 0;
    width: 100%;
    height: 100%;
    background-color: $cm_color-primary;
    transition: transform $cm_panel-speed, top $cm_panel-speed, background-color 0s;
  }
  &::before {
    top: -5px;
  }
  &::after {
    top: 5px;
  }
  // Hamburger animation
  .cm-button.cm-active & {
    background-color: rgba($cm_color-primary, 0);
    &::before,
    &::after {
      background-color: $cm_color-primary;
    }
    &::before {
      top: 0;
      transform: rotate(135deg);
    }
    &::after {
      top: 0;
      transform: rotate(225deg);
    }
  }
  // If the hamburger is next to the text
  .cm-button_text + & {
    margin-left: 5px;
  }
}

// Other Icons
// -----------------------------------------------------------------------------
.cm-icon {
  display: inline-block;
  position: absolute;
  top: 0;
  right: 0;
  font-style: normal;
  text-align: left;
  text-indent: -9999px;
  color: $cm_color-primary;
  direction: ltr;
  &::before,
  &::after {
    content: "";
    pointer-events: none;
  }
}

.cm-icon-caret {
  width: 20%;
  height: $cm_list-item-height;
  &::before,
  &::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    margin: auto 0;
    width: 7px;
    height: 1px;
    box-shadow: inset 0 0 0 32px;
    transform-origin: right;
  }
  &::before {
    transform: rotate(45deg);
  }
  &::after {
    transform: rotate(-45deg);
  }
  .cm-menu-open + & {
    right: 2px;
    &::before,
    &::after {
      top: 5px;
    }
    &::before {
      transform: rotate(-225deg);
    }
    &::after {
      transform: rotate(45deg);
    }
  }
}

.cm-icon-close {
  margin: 2px;
  width: 15px;
  height: 15px;
  transform: rotate(45deg);
  &::before,
  &::after {
    position: absolute;
    top: 50%;
    left: 50%;
    box-shadow: inset 0 0 0 32px;
    transform: translate(-50%, -50%);
  }
  &::before {
    width: 15px;
    height: 1px;
  }
  &::after {
    width: 1px;
    height: 15px;
  }
}

// For the demo
body {
  width: 100%;
  height: 100vh;
  line-height: 1.3;
  font-size: 14px;
}

button {
  background-color: #fff;
}

.demo {
  display: flex;
  height: 100%;
}

.demo-left {
  width: 60%;
  position: relative;
  padding: 20px;
  z-index: 100;
  background-color: #fff;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.demo-right {
  width: 40%;
  position: relative;
}

.demo-header {
  background-color: gray;
  position: relative;
  z-index: 100;
  height: 50px;
}

.cm-panel {
  top: 50px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  height: auto;
}
              
            
!

JS

              
                (function($) {
  'use strict';

  $.fn.clearmenu = function(options) {
    var animationSpeed, classes, settings, setUpClearMenu, revealMenu, toggleSubMenu;

    // Establish the default CSS classes to use
    classes = {
      subMenu: 'cm-submenu',
      top: 'cm-top',
      bottom: 'cm-bottom',
      left: 'cm-left',
      right: 'cm-right',
      fade: 'cm-fade',
      visible: 'cm-open',
      active: 'cm-active'
    };

    // Establish the default plug-in settings
    settings = $.extend({
      panel: this,
      trigger: '.cm-button',
      reveal: 'top',
      hasSubMenu: true,
      subMenu: '.cm-submenu',
      speed: 200,
      close: false,
      wordpress: false
    }, options);

    // Get the plug-in ready to run
    setUpClearMenu = function setUpClearMenu() {
      // Determine how to reveal the target panel
      switch (settings.reveal) {
        case 'bottom':
          $(settings.panel).addClass(classes.bottom);
          break;
        case 'left':
          $(settings.panel).addClass(classes.left);
          break;
        case 'right':
          $(settings.panel).addClass(classes.right);
          break;
        case 'fade':
          $(settings.panel).addClass(classes.fade);
          break;
        default:
          $(settings.panel).addClass(classes.top);
          break;
      }

      // Establish functionality if sub-menus are active
      if (settings.hasSubMenu) {
        animationSpeed = settings.speed;

        if (!settings.wordpress) {
          toggleSubMenu = function toggleSubMenu() {
            $(this).parent().find('ul').toggleClass('cm-menu-open').slideToggle(animationSpeed);
          };

          $(settings.panel).find('> ul ul').addClass(classes.subMenu);
          $(settings.subMenu).parent().append('<i class="cm-icon cm-icon-caret"></i>');
          $(settings.subMenu).next().on('click.clearmenu', toggleSubMenu);
        }

        if (settings.wordpress) {
          $(settings.panel).find('.menu-item-has-children').append('<i class="cm-icon cm-icon-caret"></i>');
          $('.menu-item-has-children').on('click.clearmenu', 'i', function() {
            $(this).prev('.sub-menu').slideToggle(animationSpeed);
          });
        }
      }

      // Set up the close button for the panel
      if (settings.close) {
        $(settings.panel).prepend('<i class="cm-icon cm-icon-close"></i>');
        $('.cm-icon-close').on('click', function() {
          $(settings.panel).removeClass(classes.visible);

          if ('.cm-button' === settings.trigger) {
            $(settings.trigger).removeClass('cm-active');
          }
        });
      }
    };

    // Reveal the target panel
    revealMenu = function revealMenu() {
      if ('.cm-button' === settings.trigger) {
        $(this).toggleClass('cm-active');
      }

      $(settings.panel).toggleClass(classes.visible);
      $('body').toggleClass(classes.active);
    };

    // Actually fire the plug-in
    $(settings.trigger).on('click.clearmenu', revealMenu);
    setUpClearMenu();

    // Ensure chaining of other jQuery methods
    return this;
  };
})(jQuery);

$(function() {
  $('#panel').clearmenu();
});
              
            
!
999px

Console