Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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>
  <header>
    <button>Toggle</button>
    <aside>
      <nav open="true">
        <ul>
          <li>
            <a href="#">Menu item</a>
          </li>
          <li>
            <a href="#">Menu item</a>
          </li>
          <li>
            <a href="#">Menu item</a>
          </li>
          <li>
            <a href="#">Menu item</a>
          </li>
          <li>
            <a href="#">Menu item</a>
          </li>
        </ul>
      </nav>
    </aside>

    
  </header>
  <section>
        Sit est sunt ut nostrud elit exercitation magna fugiat in ea consectetur. Nulla est ipsum ipsum tempor incididunt in eu officia cupidatat commodo eu. Dolore qui sunt eiusmod Lorem voluptate pariatur nisi nisi. Excepteur ullamco occaecat do aute cillum consequat reprehenderit minim irure. Nisi consectetur amet labore aliqua incididunt. Ullamco minim aute esse fugiat aute culpa aliquip laboris Lorem esse ipsum id.
  </section>
</main>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
html, body, main {
  height: 100vh;
  width: 100%;
  margin: 0;
}

section {
  width: 100%;
  height: 100%;
}

aside {
  background: transparent;
  position: fixed;
  z-index: 1;
  height: 100vh;
  width: 200vw;
  top: 0;
  left: 0;
  pointer-events: none;
}

nav {
  pointer-events: all;
  position: absolute;
  top: 0;
  width: 50%;
  height: 100vh;
  background: #efefef;
  border-left: 1px solid lightgrey;
  transform: translate3d(100%, 0, 0);
}
              
            
!

JS

              
                /*
You need these libraries and plugins:
GSAP - https://www.gsap.com/docs/v3/GSAP/
Draggable - https://www.gsap.com/docs/v3/Plugins/Draggable/
Inertia - https://www.gsap.com/docs/v3/Plugins/InertiaPlugin/
*/
const trigger = document.querySelector('button');
const nav = document.querySelector('nav');
let outPoint = 0;
let inPoint = 100;
let points = [inPoint, outPoint]
let open = false;
let draggable = undefined;

function getInPoint() {
  return Math.floor(nav.getBoundingClientRect().width / 10);
}

function getOutPoint() {
  return Math.floor(nav.getBoundingClientRect().width);
}

function createDrag() {
  points = [getInPoint(), getOutPoint()];

  draggable = Draggable.create("nav", {
    type: 'x',
    lockAxis: true,
    inertia: true,
    zIndexBoost: false,
    throwProps: true,
    dragClickables: true,
    autoScroll: 0,
    edgeResistance: 0.75,
    dragResistance: .2,
    minDuration: .2,
    maxDuration: .8,
    snap: { x: points},
    onDragEnd: function () {
      open = this.endX === getInPoint();
    },      
  })
}


trigger.addEventListener('click', function() {  
  open = !open;
  gsap.to(nav, {duration: 0.4, x: open ? getInPoint():getOutPoint()})
})

window.addEventListener('resize', () => {
  nav.style.setProperty('transform', `translate3d(${getInPoint()}px, 0, 0)`);
  
  
  if (draggable) {
    const points = [getInPoint(), getOutPoint()];
    draggable[0].vars.snap = { x: points};
    console.log(draggable[0])
    draggable[0].update()
  }
})

createDrag();
              
            
!
999px

Console