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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <div class="menu">
  <ul>
    <li><a href="Home">home</a></li>
    <li><p class="navItem">item 1</p>
      <ul class="subMenu subMenuOne">
        <h2>Sub Menu One</h2>
        <li><a href="sub item 1">sub item 1</a></li>
        <li><a href="sub item 2">sub item 2</a></li>
        <p class="close">Close</p>
      </ul>
    </li>
        <li><p class="navItem">item 2</p>
      <ul class="subMenu subMenuTwo">
        <h2>Sub Menu Two</h2>
        <li><a href="sub item 1">sub item 1</a></li>
        <li><a href="sub item 2">sub item 2</a></li>
        <p class="close">Close</p>
      </ul>
    </li>
        <li><p class="navItem">item 3</p>
      <ul class="subMenu subMenuThree">
        <h2>Sub Menu Three</h2>
        <li><a href="sub item 1">sub item 1</a></li>
        <li><a href="sub item 2">sub item 2</a></li>
        <p class="close">Close</p>
      </ul>
    </li>
  </ul>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  overflow: hidden;
}
.menu {
  padding: 3em;
  position: absolute;
  background: green;
  width: 30%;
  .subMenu {
    display: block;
    position: absolute;
    padding: 3em;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: #000;
    z-index: -99;
    color: white;
    width: 100%;
    // margin-left: -100%;
  }
  .subMenuOne {
    background: red;
  }
  .subMenuTwo {
    background: pink;
  }
  .subMenuThree {
    background: purple;
  }
}

li {
  padding: 1em;
}
              
            
!

JS

              
                let openItem; // stores a reference to the currently open nav item (if there is one)

// loop through all .navItem elements to set up common functionality for them all...
gsap.utils.toArray(".navItem").forEach(navItem => {
  let subMenu = navItem.parentNode.querySelector(".subMenu"),
      closeButton = subMenu.querySelector(".close"),
      isOpen = false;
  
  // add an "open()" method to the element itself for convenience
  navItem.open = () => {
    if (!isOpen) {
      isOpen = true;
      let tl = gsap.timeline();
      if (openItem) { // if there's an open nav item, close it first!
        tl.add(openItem.close());
      }
      tl.to(subMenu, {xPercent: 100, overwrite: true});
      openItem = navItem; // store this element as the currently open one
      return tl;
    }
  };
  
  navItem.close = () => {
    if (isOpen) {
      isOpen = false;
      openItem = null;
      // return a tween because we'll insert that into a timeline in the calling method
      return gsap.to(subMenu, {xPercent: 0, overwrite: true});
    }
  };
  
  navItem.toggle = () => isOpen ? navItem.close() : navItem.open();
  
  // clicking on the nav text will toggle the menu
  navItem.addEventListener("click", navItem.toggle);
  closeButton.addEventListener("click", navItem.close);
});

              
            
!
999px

Console