<h1>Isotope - stagger</h1>

<div class="button-group filter-button-group">
  <button class="button is-checked" data-filter="*">All</button>
  <button class="button" data-filter=".grid-item--red">Red</button>
  <button class="button" data-filter=".grid-item--blue">Blue</button>
</div>

<div class="grid">
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--blue"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
  <div class="grid-item grid-item--red"></div>
</div>
* { box-sizing: border-box; }

body { font-family: sans-serif; }

/* ---- button ---- */

.button {
  display: inline-block;
  padding: 0.5em 1.0em;
  background: #EEE;
  border: none;
  border-radius: 7px;
  background-image: linear-gradient( to bottom, hsla(0, 0%, 0%, 0), hsla(0, 0%, 0%, 0.2) );
  color: #222;
  font-family: sans-serif;
  font-size: 16px;
  text-shadow: 0 1px white;
  cursor: pointer;
}

.button:hover {
  background-color: #8CF;
  text-shadow: 0 1px hsla(0, 0%, 100%, 0.5);
  color: #222;
}

.button:active,
.button.is-checked {
  background-color: #28F;
}

.button.is-checked {
  color: white;
  text-shadow: 0 -1px hsla(0, 0%, 0%, 0.8);
}

.button:active {
  box-shadow: inset 0 1px 10px hsla(0, 0%, 0%, 0.8);
}

/* ---- button-group ---- */

.button-group {
  margin-bottom: 20px;
}

.button-group:after {
  content: '';
  display: block;
  clear: both;
}

.button-group .button {
  float: left;
  border-radius: 0;
  margin-left: 0;
  margin-right: 1px;
}

.button-group .button:first-child { border-radius: 0.5em 0 0 0.5em; }
.button-group .button:last-child { border-radius: 0 0.5em 0.5em 0; }

/* ---- grid ---- */

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

/* clear fix */
.grid:after {
  content: '';
  display: block;
  clear: both;
}

/* ---- .grid-item ---- */

.grid-item {
  float: left;
  width: 80px;
  height: 80px;
  background: #0D8;
  border: 2px solid #333;
  border-color: hsla(0, 0%, 0%, 0.7);
}

.grid-item--red { background: #D00; }
.grid-item--blue { background: #19F; }
// external js: isotope.pkgd.js

var $grid = $('.grid').isotope({
  itemSelector: '.grid-item',
  stagger: 30
});

$('.filter-button-group').on( 'click', '.button', function() {
  var filterValue = $(this).attr('data-filter');
  $grid.isotope({ filter: filterValue });
});

// change is-checked class on buttons
$('.button-group').each( function( i, buttonGroup ) {
  var $buttonGroup = $( buttonGroup );
  $buttonGroup.on( 'click', 'button', function() {
    $buttonGroup.find('.is-checked').removeClass('is-checked');
    $( this ).addClass('is-checked');
  });
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js
  2. https://npmcdn.com/isotope-layout@3/dist/isotope.pkgd.js