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.

            
              <h1>Masonry - animate item size, vanilla JS</h1>

<p>Click items to toggle size</p>

<div class="grid">
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
  <div class="grid-item">
    <div class="grid-item-content"></div>
  </div>
</div>

            
          
!
            
              * { box-sizing: border-box; }

body { font-family: sans-serif; }

.grid {
  background: #EEE;
  max-width: 1200px;
}

.grid-item {
  float: left;
}

/* item is invisible, but used for layout */
.grid-item,
.grid-item-content {
  width: 120px;
  height: 120px;
}

/* grid-item-content is visible, and transitions size */
.grid-item-content {
  width: 120px;
  height: 120px;
  background: #D26;
  border: 2px solid #333;
  border-color: hsla(0, 0%, 0%, 0.5);
  border-radius: 5px;
  -webkit-transition: width 0.4s, height 0.4s;
          transition: width 0.4s, height 0.4s;
}

.grid-item:hover .grid-item-content {
  border-color: white;
  background: #A2C;
  cursor: pointer;
}

/* both item and item content change size */
.grid-item.is-expanded,
.grid-item.is-expanded .grid-item-content {
  width: 360px;
  height: 240px;
}

.grid-item.is-expanded {
  z-index: 2;
}

.grid-item.is-expanded .grid-item-content {
  background: #F90;
}
            
          
!
            
              // external js: masonry.pkgd.js

var grid = document.querySelector('.grid');
var msnry = new Masonry( grid, {
  columnWidth: 120,
  itemSelector: '.grid-item'
});

grid.addEventListener( 'click', function( event ) {
  // don't proceed if item content was not clicked on
  if ( !matchesSelector( event.target, '.grid-item-content' )  ) {
    return;
  }
  var itemElem = event.target.parentNode;
  itemElem.classList.toggle('is-expanded');

  msnry.layout();
});

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

Console