Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class='page'>
  <header class='header'>
    <div class='menu-btn-container'>
      <span class='menu-btn'>Menu</span>
    </div>
    <nav class='main-menu'>
      <ul class='menu'>
        <li><a href='#'>Home</a></li>
        <li><a href='#'>Team</a></li>
        <li><a href='#'>Services</a></li>
        <li><a href='#'>About</a></li>
        <li><a href='#'>Contact</a></li>
      </ul>
      <span class='menu-close-btn'>×</span>
    </nav>
    <div class='overlay'></div>
  </header>
  <div class='main'>
    <div class='main-content'>
      <h1>Pullout Menu with Overlay</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent congue ex id purus lobortis placerat. Etiam sed convallis ipsum. Cras mattis turpis nunc, non tempus leo rutrum vel. Ut quis pulvinar justo. Praesent ut suscipit odio. Nunc sodales, arcu vitae sagittis imperdiet, odio tellus volutpat urna, eu finibus mauris elit ac sem. Nam mattis dui quis mi porttitor sagittis. Cras a rhoncus erat. Phasellus quis ultricies justo. Nam ut ante et lectus pharetra venenatis. Praesent ullamcorper pretium facilisis.</p>
      <p>Nunc et tellus tempus, cursus elit non, porttitor nibh. Nam imperdiet neque et pharetra laoreet. Praesent gravida libero sed libero malesuada porta. Duis a ipsum nec neque faucibus aliquet et id lectus. Phasellus vel condimentum magna. Nullam non metus justo. Cras vel arcu lectus. Suspendisse porttitor ipsum in enim interdum, in lacinia elit viverra. Phasellus vel neque tincidunt dui gravida ullamcorper at id erat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Quisque nec erat et urna viverra mollis. Curabitur aliquet velit quis massa porta ultrices.</p>
      <p>Suspendisse orci est, tincidunt in leo ac, pellentesque laoreet sapien. Integer vehicula massa vel interdum posuere. Etiam mauris arcu, commodo non molestie id, porttitor ac risus. Aenean ac sem sit amet ligula egestas sollicitudin. Praesent id tristique velit. Phasellus sed nulla ac neque iaculis scelerisque. Donec elit lorem, efficitur suscipit neque vel, dictum luctus erat. In hendrerit accumsan est id ullamcorper. Fusce neque felis, faucibus et felis a, cursus cursus augue.</p>
    </div>
  </div>
</div>
            
          
!
            
              /* Typography */
$fontFamily: Helvetica, Arial, sans-serif;
$rootFontSize: 16px;
$fontSize: 0.875rem;
$headerFontSize: 1.5rem;


/* Color */
$backgroundColor: #ffffff;
$menuBackgroundColor: rgba(#ffffff, 0.9);
$fontColor: #000000;
$linkFontColor: #5f5f5f;
$overlayColor: #000000;


/* Base Styles */
html {
  font-size: $rootFontSize;
}

body {
  font-family: $fontFamily;
  font-size: $fontSize;
  color: $fontColor;
  background: $backgroundColor;
}

ul {
  padding: 0;
  margin: 0;
}

li {
  list-style: none !important;
}


/* Header Styles */
.menu-btn {
  cursor: pointer;
  transition: 0.2s;
  &:hover {
    color: $linkFontColor;
  }
}


/* Navigation Styles */
.main-menu {
  position: fixed;
  top: 0;
  right: 100vw;
  width: auto;
  height: 100vh;
  background: $menuBackgroundColor;
  z-index: 20;
  overflow: auto;
}

.menu {
  padding: 1rem 5rem 0 1rem;
  white-space: nowrap;

  li {
    padding-bottom: 1rem;
  }

  a {
    display: block;
    text-decoration: none;
    transition: 0.2s;

    &:link, &:visited {
      color: $fontColor;
    }
    &:hover, &:active, &:focus {
      text-decoration: none;
      color: $linkFontColor;
    }
  }
}

.menu-close-btn {
  position: absolute;
  top: 0;
  right: 0;
  margin: 0.875rem 1rem 0 0;
  cursor: pointer;
  transition: 0.2s;
  &:hover {
    color: $linkFontColor;
  }
}


/* Overlay Styles */
.overlay {
  display: none;
  position: fixed;
  top: -20vh;
  left: -20vw;
  background: $overlayColor;
  opacity: 0;
  width: 140vw;
  height: 140vh;
  z-index: 10;
}


/* Page Styles */
h1 {
  font-size: $headerFontSize;
  text-align: center;
  font-weight: normal;
}
            
          
!
            
              jQuery(document).ready(function($) {
  
  /* Variable declaration */
  var mainMenu = $('.main-menu'),
      menuBtn = $('.menu-btn'),
      menuCloseBtn = $('.menu-close-btn'),
      overlay = $('.overlay'),
      windowVar = $(window),
      slidePos,
      slideTime = 400;
  
  /* Functions for opening and closing menu */
  function calcSlidePos(object) {
    var objectWidth = object.outerWidth();
    slidePos = (windowVar.width() - objectWidth) + "px";
  }
  
  function openMenu(menu) {
    menu.animate({right: slidePos}, slideTime)
    .removeClass("open close").addClass("open");
  }
  
  function closeMenu(menu) {
    menu.animate({right: "100vw"}, slideTime)
    .removeClass("open close").addClass("close");
  }
  
  /* Functions for overlay */
  function overlayFadeIn(overlay) {
    overlay.css({display: "block"}).animate({opacity: 0.85}, slideTime);
  }
  
  function overlayFadeOut(overlay) {
    overlay.animate({opacity: 0}, slideTime, function() {
      $(this).css({display: "none"});
    });
  }
  
  /* Page JS */
  menuBtn.click(function() {
    calcSlidePos(mainMenu);
    openMenu(mainMenu);
    overlayFadeIn(overlay);
  });
  
  menuCloseBtn.click(function() {
    closeMenu(mainMenu);
    overlayFadeOut(overlay);
  });
  
  overlay.click(function() {
    closeMenu(mainMenu);
    overlayFadeOut(overlay);
  });
  
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console