cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <h1>Packery demo - Draggabilly with appended items</h1>
<div class="packery">
  <div class="item w4 h2"></div>
  <div class="item w2 h2"></div>
  <div class="item w2 h4"></div>
  <div class="item w2 h2"></div>
  <div class="item w4 h4"></div>
  <div class="item w2 h2"></div>
  <div class="item w2 h4"></div>
  <div class="item w4 h4"></div>
  <div class="item w2 h2"></div>
  <div class="item w2 h2"></div>
</div>

<p><button id="add-items">Add more items</button>
            
          
!
            
              * {
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}

body { font-family: sans-serif; }

.packery {
  background: #FDD;
  background: hsla(45, 100%, 40%, 0.2);
  max-width: 520px;
}

/* clearfix */
.packery:after {
  content: ' ';
  display: block;
  clear: both;
}

.item {
  width: 40px;
  height: 40px;
  float: left;
  background: #C09;
  border: 4px solid #333;
  border-color: hsla(0, 0%, 0%, 0.3);
}

.item:hover {
  border-color: white;
  cursor: move;
}

.item.w2 { width:   80px; background: #9C0; }
.item.h2 { height:  80px; background: #0C9; }
.item.h4 { height: 160px; background: #C90; }
.item.w4 { width:  160px; background: #90C; }

.item.is-dragging,
.item.is-positioning-post-drag {
  border-color: white;
  background: #09F;
  z-index: 2;
}

button {
  font-size: 20px;
}
            
          
!
            
              // http://packery.metafizzy.co/packery.pkgd.js and 
// http://draggabilly.desandro.com/draggabilly.pkgd.js added as external resource

$( function() {
  var $container = $('.packery');

  $container.packery({
    columnWidth: 80,
    rowHeight: 80
  });

  // bind draggabilly events to item elements
  $container.find('.item').each( makeEachDraggable );

  function makeEachDraggable( i, itemElem ) {
    // make element draggable with Draggabilly
    var draggie = new Draggabilly( itemElem );
    // bind Draggabilly events to Packery
    $container.packery( 'bindDraggabillyEvents', draggie );
  }

  // add more items
  $('#add-items').click( function() {
    var items = '<div class="item w2 h2"></div>' +
      '<div class="item w2 h2"></div>' +
      '<div class="item w4 h2"></div>' +
      '<div class="item h4 w4"></div>' +
      '<div class="item w2 h2"></div>' +
      '<div class="item w2 h4"></div>' +
      '<div class="item w2 h2"></div>';
    var $items = $(items);
    // add to packery layout
    $container.append( $items )
      .packery( 'appended', $items )
    // make item elements draggable
    $items.each( makeEachDraggable );
  });

});

            
          
!
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