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

              
                <header class="banner">

  <button class="toggle"><span class="line"></span>
    <span class="line"></span>
    <span class="line"></span>
    <span class="line"></span>
    <span class="sr-only">Toggle
      menu</span>
  </button>

  <nav class="nav-primary" aria-label="Primary" style="">
    <div class="menu-primary-container">
      <ul id="menu-primary" class="nav">
        <li id="menu-item-149" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-149" style="transform: scale(0, 1); opacity: 0;"><a href="#">Letter from Chairman</a></li>
        <li id="menu-item-150" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-150" style="transform: scale(0, 1); opacity: 0;"><a href="#">By The Numbers</a></li>
        <li id="menu-item-151" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-151" style="transform: scale(0, 1); opacity: 0;"><a href="#">Gallery</a></li>
        <li id="menu-item-152" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-152" style="transform: scale(0, 1); opacity: 0;"><a href="#">Community Stories</a></li>
        <li id="menu-item-153" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-153" style="transform: scale(0, 1); opacity: 0;"><a href="#">Vision for Next 50 yrs</a></li>
      </ul>
    </div>
  </nav>
</header>
              
            
!

CSS

              
                $green: #186135;

.banner {
  display: flex;
  flex-wrap: wrap;
  padding-top: 1rem;
  padding-bottom: 1rem;
  width: 100%;

  button {
    margin-left: auto;
    @media only screen and (min-width: 1280px) {
      order: 3;
    }
  }

  .toggle .line {
    width: 30px;
    height: 3px;
    background-color: $green;
    display: block;
    margin: 7px 0;
    -webkit-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;

    &:nth-child(2),
    &:nth-child(3) {
      width: 36px;
    }
  }

  .toggle:hover {
    cursor: pointer;
  }

  .toggle.is-active .line:nth-child(1),
  .toggle.is-active .line:nth-child(4) {
    opacity: 0;
  }

  .toggle.is-active .line:nth-child(2) {
    transform: translate(0, 5px) rotate(45deg);
  }

  .toggle.is-active .line:nth-child(3) {
    transform: translate(0, -5px) rotate(-45deg);
  }

  .nav-primary {
    //opacity: 0;
    //visibility: hidden;

    display: flex;
    justify-content: center;
    align-items: center;

    flex: 0 0 100%;

    transform: translate3d(-100%, -100%, 0);
    //transform: scaleY(0);
    // transform-origin: center top;

    @media only screen and (min-width: 1280px) {
      opacity: 1;
      transform: none;
      flex: 1 1 auto;
    }

    ul {
      display: flex;
      flex-direction: column;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;

      li {
        text-align: center;
        margin: 0 1rem;
        opacity: 1;

        @media only screen and (min-width: 1280px) {
          opacity: 0;
        }
      }

      > a {
        color: #fff;
        font-size: 2.5rem;
      }
    }

    @media only screen and (min-width: 1280px) {
      ul {
        flex-direction: row;

        li {
          text-align: left;

          @media only screen and (min-width: 1280px) {
            transform: scaleX(0);
            transform-origin: right center;
          }
        }
      }
    }
  }
}

.sr-only {
  display: none;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger, DrawSVGPlugin, MotionPathPlugin);

const mediaQuery = "screen and (min-width: 1280px)";
const mediaQueryList = window.matchMedia(mediaQuery);

let setBodyClass = function () {
  if (mediaQueryList.matches) {
    document.body.classList.remove("mobile");
    document.body.classList.add("desktop");
    console.log("The window is now 1280px or over");
  } else {
    document.body.classList.remove("desktop");
    document.body.classList.add("mobile");
    console.log("The window is now under 1280px");
  }
};

setBodyClass();

mediaQueryList.addEventListener("change", (event) => {
  console.log(window.innerWidth);
  setBodyClass();
});

const menu = document.querySelector("header nav");

const toggleMenu = gsap.timeline({ paused: true, reversed: true });

toggleMenu
  .set(menu, { autoAlpha: 1 })
  .to(menu, {
    duration: 0,
    ease: "linear",
    transform: "translate3d(0,0,0)",
    scaleY: 1
  })
  .to("header nav li", {
    duration: 0.25,
    opacity: 1,
    reversed: true,
    scaleX: 1,
    ease: "Expo.easeInOut", //
    stagger: 0.05
  });

const toggle = gsap.utils.toArray(".toggle");

toggle.forEach((t) => {
  t.addEventListener("click", function () {
    if (toggleMenu.reversed()) {
      toggleMenu.play();
    } else {
      toggleMenu.reverse(0);
    }

    $(this).toggleClass("is-active");
  });
});

menu.addEventListener("click", function (event) {
  if (!event.target.closest("ul")) {
    toggleMenu.reverse(0);
  }
});

              
            
!
999px

Console