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.

            
              <div class="expandable">
  <button>Expand all</button>
<div class="expandable-item">
    <a class="expandable-item__header js-toggle-expand" role="tab" id="headingpanel-1" href="#panel-1" data-toggle="collapse" aria-expanded="false" aria-controls="panel-1">
        <h3 class="expandable-item__title gamma"><span class="link-text">Expandable item title</span><span class="expandable-item__icon"></span></h3>
    </a>

    <div id="panel-1" class="expandable-item__body" role="tabpanel" aria-expanded="false" aria-labelledby="panel-1">

<p>Vestibulum quis vestibulum neque, ut suscipit eros. Phasellus sagittis ipsum vitae euismod sollicitudin. Vestibulum eu nulla id nisl maximus pharetra. Vivamus bibendum placerat elit. Quisque feugiat sapien ut ante semper, at pellentesque risus laoreet. Aliquam dapibus massa vitae nisi sollicitudin, eget efficitur augue porta. Sed in sem enim.
      </p><p>
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam non est sit amet nunc eleifend ultricies. Suspendisse tristique tempus nibh, ac porttitor magna. Pellentesque urna enim, auctor et aliquet sit amet, consectetur vitae tortor. </p>

    </div>
</div>
  
  <div class="expandable-item">
    <a class="expandable-item__header js-toggle-expand" role="tab" id="headingpanel-2" href="#panel-2" data-toggle="collapse" aria-expanded="false" aria-controls="panel-2">
        <h3 class="expandable-item__title gamma"><span class="link-text">Another expandable item title</span><span class="expandable-item__icon"></span></h3>
    </a>

    <div id="panel-2" class="expandable-item__body" role="tabpanel" aria-expanded="false" aria-labelledby="panel-2">
<p>
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam non est sit amet nunc eleifend ultricies. Suspendisse tristique tempus nibh, ac porttitor magna. Pellentesque urna enim, auctor et aliquet sit amet, consectetur vitae tortor. </p>
<p>Vestibulum quis vestibulum neque, ut suscipit eros. Phasellus sagittis ipsum vitae euismod sollicitudin. Vestibulum eu nulla id nisl maximus pharetra. Vivamus bibendum placerat elit. Quisque feugiat sapien ut ante semper, at pellentesque risus laoreet. Aliquam dapibus massa vitae nisi sollicitudin, eget efficitur augue porta. Sed in sem enim.
      </p>

    </div>
</div>
</div>
            
          
!
            
              'use strict';

var Expandable = {
  init: function() {
    var that = this;

    that.expandable = $('.expandable');
    
    
    
    that.expandable.on('click', 'button', function (event) {
      var expandButton = $(this);
      
      expandButton.toggleClass('open');
      
      if (expandButton.hasClass('open')) {
        expandButton.text('Close all');
        that.expandable.find('.expandable-item').addClass('expandable-item--open') 
      that.expandable.find('.expandable-item__body').show()
      } else {
        expandButton.text('Expand all');
        that.expandable.find('.expandable-item').removeClass('expandable-item--open') 
        that.expandable.find('.expandable-item__body').hide()
      }
    });
    
    

    //Handle changing display on panel headers when open
    that.expandable.on('click', '.js-toggle-expand', function(event) {

      event.preventDefault();

      var expandableItem = $(this).closest('.expandable-item');

      if (expandableItem.hasClass('expandable-item--open')) {
        that.closeExpandableItem(expandableItem);

      } else {
        if (that.expandable.hasClass('expandable--single')) {
          that.closeExpandableItem(expandableItem.siblings('.expandable-item'));
        }
        that.openExpandableItem(expandableItem);
      }
    });
  },

  openExpandableItem: function(expandableItem) {
    var expandableItemBody = expandableItem.find('.expandable-item__body');

    expandableItemBody.attr('aria-expanded', 'true');
    expandableItem.addClass('expandable-item--open');
    expandableItemBody.slideDown(200, function() {
      // hacky IE8 fix to force redraw of changed inline-block element
      expandableItem.closest('.grid__item').toggleClass('foo');
      expandableItem.closest('.grid__item').toggleClass('foo');
    });
  },

  closeExpandableItem: function(expandableItem) {
    var expandableItemBody = expandableItem.find('.expandable-item__body');

    expandableItemBody.attr('aria-expanded', 'false');
    expandableItem.removeClass('expandable-item--open');
    expandableItemBody.slideUp(200, function() {
      // hacky IE8 fix to force redraw of changed inline-block element
      expandableItem.closest('.grid__item').toggleClass('foo');
      expandableItem.closest('.grid__item').toggleClass('foo');
    });
  },

  showAllExpandableItems: function() {
    var expandableItems = this.expandable.find('.expandable-item');

    for (var i = 0, il = expandableItems.length; i < il; i++) {
      this.openExpandableItem($(expandableItems[i]));
    }
  }
};

// initialize
Expandable.init();
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console