cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="topMenu">
  <h1>Buttons are awesome!</h1>
  <p>This animated button can be toggled via JS to create a smooth, intuitive transition for the user.</p>
  <div class="menuButton">
    <div class="bar"></div>
  </div>
</div>

<div class="sideMenu">
  <h1>Easy to keep track of!</h1>
  <p>This menu uses transforms.</p>
  <p><span>Fork and enhance!</span></p>
  <div class="menuButton">
    <!--<div class="topBar"></div> -->
    <div class="bar"></div>
    <!-- <div class="bottomBar"></div> -->
  </div>
</div>



<div class="instructions">
  <h1>Animated Menu/Close Button</h1>
  <p>Click the &#9776; button to see it change. Click the <b>&times;</b> button to close the menu and restore the icon state back again.
  </p>
</div>
            
          
!
            
              @import "compass/css3";

@import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,600);
* {@include box-sizing(border-box);}
body{background-color: #eee;}

$buttonSize: 3em; // <-- Change this to resize
$barHeight: $buttonSize/12;

h1 {
  font-family: "Open Sans", sans-serif;
  font-size: 1em;
  font-weight: 600;
  padding: 0;
  margin: 0;
  line-height: 1em;
}
p {
  font-family: "Open Sans", sans-serif;
  font-weight: 300;
  span {
    font-weight: 400;
  }
}

.sideMenu, .topMenu {
  background: #fff;
  padding: 1em;
  position: absolute;
}
.sideMenu {
  //Trying out transforms for this menu.
  height: 15em;
  width: 10em;
  left: -10.125em;
  top: 1em;
  border: $buttonSize/12 solid #222;
  transform: translate(1em);
  transition: transform 0.55s cubic-bezier(1,0,0,1);
  &.visible {
    transform: translate(9.75em); 
  }
  .menuButton {
    right: -$buttonSize;
    top: 1em;
  }
}

.topMenu {
  width: 15em;
  height: 10em;
  top: -9.125em;
  left: 8em;
  border: $buttonSize/12 solid #222;
  transition: top 0.55s cubic-bezier(1,0,0,1);
  &.visible {
    top: -$buttonSize/12;
  }
  .menuButton {
    bottom: -$buttonSize;
    right: -$buttonSize/12;
  }
}

.menuButton {
  width: $buttonSize;
  height: $buttonSize;
  position: absolute;
  border: $buttonSize/12 solid #222;
  background: #fff;
  cursor: pointer;
  font-size: 100%;
  
  .bar:before, .bar:after, .bar {
    position: relative;
    width: $buttonSize*(7/12);
    height: $buttonSize/12;
    background-color: #222;
    transition: 0.2s ease;
    content:"";
  }
  
  .bar:before {
    position: absolute;
    top: -$buttonSize*(1/6);
  }
  .bar {
    top: 50%;
    margin: -($barHeight/3)*2 0 0 $buttonSize/8;
  }
  .bar:after {
    position: absolute;
    top: $buttonSize*(1/6);
  }
} //END menuButton


.close {
  .bar:before, .bar:after, .bar {
    margin: 0 auto;
    transform: translateZ(0);
    // Keeps page from flashing in Mac Webkit
  }
  .bar:before, .bar:after{
    top: 50%;
    margin-top: -$buttonSize/12;
    margin-left: $buttonSize/8;
    transform-origin: 50% 50%;
  }
  .bar:before {
    transform: rotate(45deg);
  }
  .bar:after {
    transform: rotate(-45deg);
  }
  .bar {
    background: transparent;
    margin-left: 0;
    height: 0;
    top: 55%;
  }
} //END close



.instructions {
  background: #fff;
  width: 20em;
  min-height: 10em;
  border: $buttonSize/24 solid #000;
  padding: 1em 1em 0.25em 1em;
  margin: 6em 3em;
}
            
          
!
            
              $(".menuButton").click(function() {
  $(this).toggleClass("close");
  $(this).parent("div").toggleClass("visible");
});


            
          
!
999px
Loading ..................

Console