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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <!-- Wrapper -->
<div id="menu-icon-wrapper" class="menu-icon-wrapper">
    <!-- SVG element with paths -->
    <svg width="100px" height="100px">
        <path class="outer-bar" d="M 30 40 L 70 40 C 90 40 90 75 60 85 A 40 40 0 0 1 20 20 L 80 80" opacity="0"/>
        <path class="inner-bar" d="M 30 50 L 70 50" opacity="0" />
        <path class="outer-bar" d="M 30 40 L 70 40 C 90 40 90 75 60 85 A 40 40 0 0 1 20 20 L 80 80" transform="rotate(180 50 50) scale(-1, 1) translate(-100 0)" opacity="0" />
    </svg>
    <!-- Trigger to perform the animations -->
    <button id="menu-icon-trigger" class="menu-icon-trigger"></button>
</div>
            
          
!
            
              $size: 34px;

body {
    background: #333;
}

// The wrapper was defined with a fixed width and height
// Note, that the pointer-events property is set to 'none'. 
// We don't need any pointer events in the entire element.
.menu-icon-wrapper{
    position: relative;
    display: inline-block;
    width: $size;
    height: $size;
    pointer-events: none;
    transition: 0.1s;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -$size / 2;
    margin-top: -$size / 2;
}

// To perform the scaled transform for the second demo
.menu-icon-wrapper.scaled{
    transform: scale(0.5);
}

// Adjusting the position of the SVG element
.menu-icon-wrapper svg{
    position: absolute;
    top: -33px;
    left: -33px;
}

// Defining the styles for the path elements
.menu-icon-wrapper svg path{
    stroke: #fff;
    stroke-width: 4px;
    stroke-linecap: round;
    fill: transparent;
}

// Setting the pointer-events property to 'auto', 
// and allowing only events for the trigger element
.menu-icon-wrapper .menu-icon-trigger{
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    pointer-events: auto;
    background: none;
    border: none;
    margin: 0;
    padding: 0;
    outline: none;
    
    &:active,
    &:focus {
        outline: none
    }
}


            
          
!
            
              /*
    This exercise has been a good example of why we need to
    put absolute path measurements in the roadmap :)
*/
// States
var isHamburger = true,
    outerBarLength = 10, // in percent
    innerBarLength = 72,
    hamburgerOuterBar = {
        length: outerBarLength,
        offset: 2,
        opacity: 1
    },
    hamburgerInnerBar = {
        opacity: 1,
        length: innerBarLength,
        offset: 14.9
    },
    crossOuterBar = {
        length: outerBarLength,
        offset: 80.3
    },
    crossInnerBar = {
        length: 0,
        offset: 50,
        opacity: 0
    };

// Select elements and set initial state
var outerBars = ui.select('.outer-bar', { values: hamburgerOuterBar }).each('sync'),
    innerBar = ui.select('.inner-bar', {  values: hamburgerInnerBar }).sync();

// Tweens
var outerBaseTween = new ui.Tween({
        duration: 600,
        ease: 'backOut'
    }),
    outerToCross = outerBaseTween.extend({
        values: crossOuterBar
    }),
    outerToHamburger = outerBaseTween.extend({
        values: hamburgerOuterBar
    }),
    innerToCross = new ui.Tween({
        ease: 'backIn',
        values: crossInnerBar
    }),
    innerToHamburger = new ui.Tween({
        ease: 'backOut',
        values: hamburgerInnerBar
    });

$('body').on('click', '.menu-icon-trigger', function (e) {
    if (isHamburger) {
        outerBars.stagger(outerToCross, 100);
        innerBar.start(innerToCross);
        isHamburger = false;
    } else {
        outerBars.stagger(outerToHamburger, 100);
        innerBar.start(innerToHamburger);
        isHamburger = true;
    }
});
            
          
!
999px
Loading ..................

Console