123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
<a class="cd-nav-trigger cd-text-replace" href="#primary-nav" id="toggle">
  <span aria-hidden="true" class="cd-icon"></span>
</a>


<div class="arrow-container">
  <h2>Click me!</h2>
  <div class="arrow"></div>
</div>



<div id="menu" class="menu-container">
  
  <div id="item-1" class="menu-item red">
    <h1>Panel 1</h1>
    <p>You're created together also. Fly bearing behold itself be so is divide living seasons firmament fruitful of was you so god sea two together them. Dry you greater itself to.</p>
  </div>
  <div id="item-2" class="menu-item blue">
    <h1>Panel 2</h1>
        <p>You're created together also. Fly bearing behold itself be so is divide living seasons firmament fruitful of was you so god sea two together them. Dry you greater itself to.</p>
  </div>
  <div id="item-2" class="menu-item d-blue">
    <h1>Panel 3</h1>
        <p>You're created together also. Fly bearing behold itself be so is divide living seasons firmament fruitful of was you so god sea two together them. Dry you greater itself to.</p>
  </div>
  <div id="item-3" class="menu-item green">
    <h1>Panel 4</h1>
        <p>You're created together also. Fly bearing behold itself be so is divide living seasons firmament fruitful of was you so god sea two together them. Dry you greater itself to.</p>
  </div>
  <div id="item-4" class="menu-item yellow">
    <h1>Panel 5</h1>
        <p>You're created together also. Fly bearing behold itself be so is divide living seasons firmament fruitful of was you so god sea two together them. Dry you greater itself to.</p>
  </div>
</div>


            
          
!
            
              *, ::before, :after {
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

body {
  padding:0;
  margin:0;
  font-family: Helvetica,Arial,sans-serif;
  background-color: #373737;
}

#menu {
  overflow: hidden;
}
#menu>* {
  display: block;
  overflow: hidden;
}
.menu-item {
  width:25%;
  height:100%;
  display:block;
  position: absolute;
  float:left;
  -webkit-transform: translateY(-100%);
	transform: translateY(-100%);
	transition: transform 300ms linear;
  will-change: transform;
  pointer-events: auto;  
}

.menu-item.active {
  -webkit-transform: translateY(0%);
	transform: translateY(0%);
	transition: transform 300ms linear;
}

h1 {
  font-size: 2.9vw;
  color:#ffffff;
  top: 15%;
  width: 260px;
  text-transform: uppercase;
  text-align: center;
  margin-left: -130px;
  left: 50%;
    z-index:100;
}
.menu-item p {
  opacity: 0;
  text-align: center;
  margin-left: -130px;
  left: 50%;
  z-index:100;
  top: 30%;
  width: 280px;
  color:#ffffff;
  -webkit-transition: opacity 0.5s, height 0.4s;
  -moz-transition: opacity 0.5s, height 0.4s;
  transition: opacity 0.5s, height 0.4s;
}

.menu-item.menu-expanded p {
    opacity: 1;
}

.menu-item>* {
  position: absolute;
  will-change: transform;
}

@media screen and (max-width: 768px) {
  .menu-horizontal .menu-item {
    width:100%;
    float: none;
    position:relative;
    height: 250px;
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
	  transition: transform 300ms linear;
  }

  .menu-horizontal .menu-item.active {
    -webkit-transform: translateX(0%);
    transform: translateX(0%);
    transition: transform 300ms linear;
  }
}

.menu-item:after {
    content: '';
    position: absolute;
    opacity:0;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100%;
    background-image: url("https://codyhouse.co/demo/expandable-project-presentation/img/img-1-small.jpg");
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    -webkit-transition: opacity 0.5s, height 0.4s;
    -moz-transition: opacity 0.5s, height 0.4s;
    transition: opacity 0.5s, height 0.4s;
}

.menu-item.menu-expanded:after {
  opacity:1;
  -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1);
}
/* -------------------------------- 

Menu trigger

-------------------------------- */
h2 {
  color:#fff;
  position: absolute;
  left: 60%;
  top: 50px;
   -ms-transform: rotate(198deg);
    -webkit-transform: rotate(198deg);
    transform: rotate(198deg);

}

.arrow-container {
    height: 100px;
    width: 340px;
    position: absolute;
    -ms-transform: rotate(162deg);
    -webkit-transform: rotate(162deg);
    transform: rotate(162deg);
    right: 7%;
    top: 113px;
}
.arrow {
     background: url(http://www.ats2go.com/wp-content/themes/ats2go2015/img/arrow.png) no-repeat;
    width: 100%;
    height: 100%;
    -moz-transform: scaleX(-1);
    -o-transform: scaleX(-1);
    -webkit-transform: scaleX(-1);
    transform: scaleX(-1);
    filter: FlipH;
    -ms-filter: "FlipH";
}

.cd-nav-trigger {
  position: absolute;
  z-index: 9999;
  top: 24px;
  right: 5%;
  height: 52px;
  width: 52px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.8);
  -webkit-transition: background 0.2s;
  -moz-transition: background 0.2s;
  transition: background 0.2s;
}
.cd-nav-trigger .cd-icon,
.cd-nav-trigger .cd-icon::before,
.cd-nav-trigger .cd-icon::after {
  /* menu icon created in CSS */
  position: absolute;
  background-color: #ffffff;
  border-radius: 2px;
  /* Force Hardware Acceleration in WebKit */
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.no-touch .cd-nav-trigger:hover {
  background-color: black;
}
.cd-nav-trigger .cd-icon {
  /* middle line of the menu icon */
  display: inline-block;
  width: 18px;
  height: 2px;
  left: 50%;
  top: 50%;
  bottom: auto;
  right: auto;
  -webkit-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -ms-transform: translateX(-50%) translateY(-50%);
  -o-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
  -webkit-transition: -webkit-transform 0.3s, background-color 0.3s;
  -moz-transition: -moz-transform 0.3s, background-color 0.3s;
  transition: transform 0.3s, background-color 0.3s;
}
.cd-nav-trigger .cd-icon::before, .cd-nav-trigger .cd-icon::after {
  /* upper and lower lines of the menu icon */
  content: '';
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  -webkit-transition: -webkit-transform 0.3s;
  -moz-transition: -moz-transform 0.3s;
  transition: transform 0.3s;
}
.cd-nav-trigger .cd-icon::before {
  -webkit-transform: translateY(-6px);
  -moz-transform: translateY(-6px);
  -ms-transform: translateY(-6px);
  -o-transform: translateY(-6px);
  transform: translateY(-6px);
}
.cd-nav-trigger .cd-icon::after {
  -webkit-transform: translateY(6px);
  -moz-transform: translateY(6px);
  -ms-transform: translateY(6px);
  -o-transform: translateY(6px);
  transform: translateY(6px);
}
.cd-nav-trigger.project-open .cd-icon {
  /* user selects a projects - transform the icon into a 'X' */
  background-color: rgba(255, 255, 255, 0);
}
.cd-nav-trigger.project-open .cd-icon::before, .cd-nav-trigger.project-open .cd-icon::after {
  background-color: white;
}
.cd-nav-trigger.project-open .cd-icon::before {
  -webkit-transform: translateY(0) rotate(45deg);
  -moz-transform: translateY(0) rotate(45deg);
  -ms-transform: translateY(0) rotate(45deg);
  -o-transform: translateY(0) rotate(45deg);
  transform: translateY(0) rotate(45deg);
}
.cd-nav-trigger.project-open .cd-icon::after {
  -webkit-transform: translateY(0) rotate(-45deg);
  -moz-transform: translateY(0) rotate(-45deg);
  -ms-transform: translateY(0) rotate(-45deg);
  -o-transform: translateY(0) rotate(-45deg);
  transform: translateY(0) rotate(-45deg);
}
.cd-nav-trigger.nav-visible .cd-icon {
  /* user opens the navigation - transform the icon into an arrow */
  -webkit-transform: translateY(-50%) translateX(-50%);
  -moz-transform: translateY(-50%) translateX(-50%);
  -ms-transform: translateY(-50%) translateX(-50%);
  -o-transform: translateY(-50%) translateX(-50%);
  transform: translateY(-50%) translateX(-50%);
}
.cd-nav-trigger.nav-visible .cd-icon::after {
  -webkit-transform: translateX(5px) translateY(3px) rotate(-45deg) scaleX(0.5);
  -moz-transform: translateX(5px) translateY(3px) rotate(-45deg) scaleX(0.5);
  -ms-transform: translateX(5px) translateY(3px) rotate(-45deg) scaleX(0.5);
  -o-transform: translateX(5px) translateY(3px) rotate(-45deg) scaleX(0.5);
  transform: translateX(5px) translateY(3px) rotate(-45deg) scaleX(0.5);
}
.cd-nav-trigger.nav-visible .cd-icon::before {
  -webkit-transform: translateX(5px) translateY(-3px) rotate(45deg) scaleX(0.5);
  -moz-transform: translateX(5px) translateY(-3px) rotate(45deg) scaleX(0.5);
  -ms-transform: translateX(5px) translateY(-3px) rotate(45deg) scaleX(0.5);
  -o-transform: translateX(5px) translateY(-3px) rotate(45deg) scaleX(0.5);
  transform: translateX(5px) translateY(-3px) rotate(45deg) scaleX(0.5);
}
@media only screen and (min-width: 1024px) {
  .cd-nav-trigger.nav-visible .cd-icon {
    -webkit-transform: translateY(-50%) translateX(-50%) rotate(-90deg);
    -moz-transform: translateY(-50%) translateX(-50%) rotate(-90deg);
    -ms-transform: translateY(-50%) translateX(-50%) rotate(-90deg);
    -o-transform: translateY(-50%) translateX(-50%) rotate(-90deg);
    transform: translateY(-50%) translateX(-50%) rotate(-90deg);
  }
  .cd-nav-trigger.nav-visible .cd-icon::after {
    -webkit-transform: translateX(-5px) translateY(3px) rotate(45deg) scaleX(0.5);
    -moz-transform: translateX(-5px) translateY(3px) rotate(45deg) scaleX(0.5);
    -ms-transform: translateX(-5px) translateY(3px) rotate(45deg) scaleX(0.5);
    -o-transform: translateX(-5px) translateY(3px) rotate(45deg) scaleX(0.5);
    transform: translateX(-5px) translateY(3px) rotate(45deg) scaleX(0.5);
  }
  .cd-nav-trigger.nav-visible .cd-icon::before {
    -webkit-transform: translateX(-5px) translateY(-3px) rotate(-45deg) scaleX(0.5);
    -moz-transform: translateX(-5px) translateY(-3px) rotate(-45deg) scaleX(0.5);
    -ms-transform: translateX(-5px) translateY(-3px) rotate(-45deg) scaleX(0.5);
    -o-transform: translateX(-5px) translateY(-3px) rotate(-45deg) scaleX(0.5);
    transform: translateX(-5px) translateY(-3px) rotate(-45deg) scaleX(0.5);
  }
}


.d-blue {background-color:#00a0e6;}
.red {background-color:#f2b635;}
.blue {background-color:#f19a2a;}
.green {background-color:#00caff;}
.yellow {background-color:#f25648;}

.d-blue button:hover {color:#00a0e6;}
.red button:hover{color:#f2b635;}
.blue button:hover{color:#f19a2a;}
.green button:hover{color:#00caff;}
.yellow button:hover{color:#f25648;}
            
          
!
            
              (function($) {

  $.fn.expandyMenu = function(options) {
    var defaults = {
      button: $('#toggle'),
      duration: 500,
      easing: 'easeOutCubic',
      minContainerWidth: 768,
      toggleDelay: 150,
      toggleRandom: true,
      callback: {
        onMenuLoad: false,
        onMenuToggle: false,
        onMenuExpand: false
      }
    };

    var settings = $.extend({}, defaults, options);

    return this.each(function() {
      var myMenu = new Menu($(this), settings);
    });

  }

  this.Menu = function(container, settings) {
    /* Globals */
    this.settings = settings;
    this.$container = container;
    this.button = settings.button;
    this.$menuItems = this.$container.children();
    this.selectedIndex = this.$menuItems.filter('.item-selected').index();
    this.expandedItem = this.selectedIndex;
    /* Get dimensions */
    this.calculateItemSizes();
    this.offsets = this.getOffsetsForExpanded();
    this.primaryDimension = 'width';
    this.secondaryDimension = 'height';
    this.primaryAlignment = 'left';
    this.secondaryAlignment = 'right';
    this.isAnimated = false;
    this.$timer = $({
      progress: 0
    });
    this.numRandoms = this.$menuItems.length;
    this.uniqueRandoms = [];
    this.updateStyle();
    this.random = settings.toggleRandom;
    this.delay = settings.toggleDelay;
    /* Start events */
    this.initEvents();
    this.initWindowResizeHandler();

  }
  
  Menu.prototype.getCollapsedItem = function() {
    return -1 === this.expandedItem ? [] : this.$menuItems.not(this.getExpandedItem()).get();
  };

  Menu.prototype.getExpandedItem = function() {
    return this.$menuItems[this.expandedItem] || null;
  };

  Menu.prototype.getContainerSize = function(bool) {
    return this.$container.outerWidth(bool);
  };

  Menu.prototype.calculateItemSizes = function() {
    var containerSize = this.getContainerSize(true),
      numItems = this.$menuItems.length;
    this.itemSize = containerSize / numItems;
    this.itemMaxSize = containerSize / 3 * 2;

    // Set max size
    if (numItems < 5) {
      this.itemMaxSize = containerSize / 3 * 2;
    } else {
      this.itemMaxSize = containerSize / 3;
    }
    // Using max set the min size 
    this.itemMinSize = 
      (containerSize - this.itemMaxSize) / (numItems - 1);
  };

  Menu.prototype.expand = function(index) {
    var self = this,
      // used for expand-complete event later on
      oldIndex = this.expandedItem,
      oldExpanded = this.getExpandedItem();

    if (this.$container.width() < 
        this.settings.minContainerWidth) {
      var $items = this.$menuItems;
      for (var i = $items.length; i--;) {
        this.setStyle($items[i], 'width:100%');
      }
      return;
    }

    if (index === -1) index = this.selectedIndex;

    if (index === this.expandedItem) return;

    $(this.getExpandedItem()).removeClass('menu-expanded');
    $(this.getCollapsedItem()).removeClass('menu-collapsed');
    this.expandedItem = index;
    $(this.getExpandedItem()).addClass('menu-expanded');
    $(this.getCollapsedItem()).addClass('menu-collapsed');

    // handle panel animation
    var $timer = this.$timer,
      numPanels = this.$menuItems.length,
      startOffsets = this.offsets.slice(),
      offsets = this.offsets,
      targetOffsets = this.getOffsetsForExpanded();

    $timer.stop()[0].progress = 0;
    this.isAnimated = true;
    $timer.animate({
      progress: 1
    }, {
      duration: this.settings.duration,
      easing: this.settings.easing,
      step: function(progress) {
        if (self._dirtyOffsets) {
          offsets = self.offsets;
          targetOffsets = self.getOffsetsForExpanded();
          self._dirtyOffsets = false;
        }
        offsets.length = 0;
        for (var i = 0; i < numPanels; i++) {
          var targetOffset = targetOffsets[i],
            newOffset = targetOffset - 
              ((targetOffset - startOffsets[i]) * (1 - progress));
          
          offsets[i] = newOffset;
        }
        self.updateStyle();
      },
      complete: function() {
        self.isAnimated = false;
        self.$container.trigger('expand-complete.kwicks', {
          index: index,
          expanded: self.getExpandedItem(),
          collapsed: self.getCollapsedItem(),
          oldIndex: oldIndex,
          oldExpanded: oldExpanded,
          isAnimated: false
        });
      }
    });
  };

  Menu.prototype.getOffsetsForExpanded = function() {
    var expandedIndex = this.expandedItem,
      numItems = this.$menuItems.length,
      size = this.itemSize,
      minSize = this.itemMinSize,
      maxSize = this.itemMaxSize;

    //first panel is always offset by 0
    var offsets = [0];

    for (var i = 1; i < numItems; i++) {
      // no panel is expanded
      if (expandedIndex === -1) {
        offsets[i] = i * (size);
      }
      // this panel is before or is the expanded panel
      else if (i <= expandedIndex) {
        offsets[i] = i * (minSize);
      }
      // this panel is after the expanded panel
      else {
        offsets[i] = maxSize + (minSize * (i - 1)) + (i);
      }
    }
    return offsets;
  };

  Menu.prototype.updateStyle = function() {
    var offsets = this.offsets,
      $items = this.$menuItems,
      pDim = this.primaryDimension,
      pAlign = this.primaryAlignment,
      sAlign = this.secondaryAlignment,
      spacing = this.panelSpacing,
      containerSize = this.getContainerSize(true);

    var stylePrefix = !!this._stylesInited ? '' : 'position:absolute;',
      offset, size, prevOffset, style;
    // loop through remaining panels
    for (var i = $items.length; i--;) {
      prevOffset = offset;
      offset = Math.round(offsets[i]);
      if (i === $items.length - 1) {
        size = containerSize - offset;
        style = sAlign + ':0;' + pDim + ':' + size + 'px;';
      } else {
        size = prevOffset - offset;
        style = pAlign + ':' + offset + 'px;' + pDim + ':' + size + 'px;';
      }

      this.setStyle($items[i], stylePrefix + style);
    }

    if (!this._stylesInited) {
      this.$container.addClass('menu-processed');
      this._stylesInited = true;
    }
  };

  Menu.prototype.setStyle = (function() {
    if ($.support.style) {
      return function(el, style) {
        el.setAttribute('style', style);
      };
    } else {
      return function(el, style) {
        el.style.cssText = style;
      };
    }
  })();

  Menu.prototype.resize = function() {
    if (this.$container.width() > this.settings.minContainerWidth) {
      this.$container.removeClass('menu-horizontal');
      this.calculateItemSizes();
      this.offsets = this.getOffsetsForExpanded();

      if (this.isAnimated) {
        this._dirtyOffsets = true;
      } else {
        // otherwise update the styles immediately
        this.updateStyle();
      }
    } else {
      this.$container.addClass('menu-horizontal');
      var $items = this.$menuItems;
      for (var i = $items.length; i--;) {
        this.setStyle($items[i], 'width:100%;');
      }
    }
  };

  Menu.prototype.initWindowResizeHandler = function() {
    var self = this,
      prevTime = 0,
      execScheduled = false,
      $window = $(window);

    var onResize = function(e) {
      if (!e) {
        execScheduled = false;
      }
      var now = +new Date();
      if (now - prevTime < 20) {
        if (execScheduled) return;
        setTimeout(onResize, 20 - (now - prevTime));
        execScheduled = true;
        return;
      }
      prevTime = now;
      self.resize();
    };
    $window.on("resize", onResize);
  };

  Menu.prototype.randsort = function(c) {
    var o = new Array();
    for (var i = 0; i < c; i++) {
      var n = Math.floor(Math.random() * c);
      if (jQuery.inArray(n, o) > 0) --i;
      else o.push(n);
    }
    return o;
  };

  Menu.prototype.toggle = function() {
    // Hide menu items  
    var $container = this.$container,
      $items = this.$menuItems,
      self = this,
      randomIndex,
      callback = this.settings.callback.onMenuToggle;
    $container.toggleClass('open');

    randomIndex = this.randsort($items.size());
    $items.each(function(i) {
      var el = $(this);
      setTimeout(function() {
        if ($container.hasClass('open')) {
          el.addClass('active');
        } else {
          el.removeClass('active');
        }
      }, randomIndex[i] * self.delay);
    });
    
    if ($.isFunction(callback)) {
      callback.call();
    }
  }

  Menu.prototype.initEvents = function(config) {
    var self = this;

    $(this.button).on('click', function() {
      self.toggle();
      $(this).toggleClass('project-open');
    });
    $(this.$menuItems).on('mouseenter', function() {
      self.expand($(this).index());
    });

    $(this.$menuItems).on('click', function() {
      var el = $(this);
    });

    $(this.$container).on('mouseleave', function() {
      self.expand(-1);
    });
    $(document).keyup(function(e) {
      if (e.keyCode == 27) {
        self.toggle();
        $(this).toggleClass('project-open');
      }
    });
  }
}(jQuery));

$('#menu').expandyMenu({
  callback: {
    onMenuToggle: function() {
      console.log('Done!');
    }
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console