Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Packery - 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>

              
            
!

CSS

              
                * { 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: #C09;
  border: 2px solid hsla(0, 0%, 0%, 0.5);
  -webkit-transition: width 0.4s, height 0.4s;
          transition: width 0.4s, height 0.4s;
}

.grid-item:hover .grid-item-content {
  background: #C90;
  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: #0C9;
}
              
            
!

JS

              
                // external js: packery.pkgd.js, classie.js

var grid = document.querySelector('.grid');
var pckry = new Packery( grid, {
  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;
  var isExpanded = itemElem.classList.contains('is-expanded');
  itemElem.classList.toggle('is-expanded');
  if ( isExpanded ) {
    // if shrinking, shiftLayout
    pckry.shiftLayout();
  } else {
    // if expanding, fit it
    pckry.fit( itemElem );
  }
});

              
            
!
999px

Console