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>Isotope - combination filters with a function, vanilla JS</h1>

<div id="filters">

  <div class="ui-group">
    <h3>Color</h3>
    <div class="button-group js-radio-button-group" data-filter-group="color">
      <button class="button is-checked" data-filter="">any</button>
      <button class="button" data-filter=".red">red</button>
      <button class="button" data-filter=".blue">blue</button>
      <button class="button" data-filter=".yellow">yellow</button>
    </div>
  </div>

  <div class="ui-group">
    <h3>Number</h3>
    <div class="button-group js-radio-button-group" data-filter-group="size">
      <button class="button is-checked" data-filter="">any</button>
      <button class="button" data-filter="greaterThan50">> 50</button>
      <button class="button" data-filter="even">even</button>
    </div>
  </div>

</div>

<div class="grid">
  <div class="color-shape small round red"><p class="number">19</p></div>
  <div class="color-shape small round blue"><p class="number">56</p></div>
  <div class="color-shape small round yellow"><p class="number">47</p></div>
  <div class="color-shape small square red"><p class="number">38</p></div>
  <div class="color-shape small square blue"><p class="number">2</p></div>
  <div class="color-shape small square yellow"><p class="number">14</p></div>
  <div class="color-shape wide round red"><p class="number">95</p></div>
  <div class="color-shape wide round blue"><p class="number">46</p></div>
  <div class="color-shape wide round yellow"><p class="number">94</p></div>
  <div class="color-shape wide square red"><p class="number">67</p></div>
  <div class="color-shape wide square blue"><p class="number">52</p></div>
  <div class="color-shape wide square yellow"><p class="number">23</p></div>
  <div class="color-shape big round red"><p class="number">48</p></div>
  <div class="color-shape big round blue"><p class="number">31</p></div>
  <div class="color-shape big round yellow"><p class="number">88</p></div>
  <div class="color-shape big square red"><p class="number">47</p></div>
  <div class="color-shape big square blue"><p class="number">16</p></div>
  <div class="color-shape big square yellow"><p class="number">27</p></div>
  <div class="color-shape tall round red"><p class="number">6</p></div>
  <div class="color-shape tall round blue"><p class="number">91</p></div>
  <div class="color-shape tall round yellow"><p class="number">75</p></div>
  <div class="color-shape tall square red"><p class="number">36</p></div>
  <div class="color-shape tall square blue"><p class="number">48</p></div>
  <div class="color-shape tall square yellow"><p class="number">38</p></div>
</div>

              
            
!

CSS

              
                * { 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: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;
}

/* ui group */

.ui-group {
  display: inline-block;
}

.ui-group h3 {
  display: inline-block;
  vertical-align: top;
  line-height: 32px;
  margin-right: 0.2em;
  font-size: 16px;
}

.ui-group .button-group {
  display: inline-block;
  margin-right: 20px;
}

/* color-shape */

.color-shape {
  width: 70px;
  height: 70px;
  margin: 5px;
  float: left;
}
 
.color-shape.round {
  border-radius: 35px;
}
 
.color-shape.big.round {
  border-radius: 75px;
}
 
.color-shape.red { background: red; }
.color-shape.blue { background: blue; }
.color-shape.yellow { background: yellow; }
 
.color-shape.wide, .color-shape.big { width: 150px; }
.color-shape.tall, .color-shape.big { height: 150px; }

.color-shape .number {
  text-align: center;
  font-size: 24px;
  margin: 22px 0 0;
}
              
            
!

JS

              
                // filter functions
var filterFns = {
  greaterThan50: function( itemElem ) {
    var number = itemElem.querySelector('.number').textContent;
    return parseInt( number, 10 ) > 50;
  },
  even: function( itemElem ) {
    var number = itemElem.querySelector('.number').textContent;
    return parseInt( number, 10 ) % 2 === 0;
  }
};

// store filter for each group
var filters = {};

// init Isotope
var iso = new Isotope( '.grid', {
  itemSelector: '.color-shape',
  filter: function( itemElem ) {

    var isMatched = true;

    for ( var prop in filters ) {
      var filter = filters[ prop ];
      // use function if it matches
      filter = filterFns[ filter ] || filter;
      // test each filter
      var filterType = typeof filter;
      if ( filter && filterType == 'function' ) {
        isMatched = filter( itemElem );
      } else if ( filter ) {
        isMatched = matchesSelector( itemElem, filter );
      }
      // break if not matched
      if ( !isMatched ) {
        break;
      }
    }
    return isMatched;
  }
  
})

document.querySelector('#filters').addEventListener( 'click', function( event ) {
  // only work with buttons
  if ( !matchesSelector( event.target, 'button' ) ) {
    return;
  }
  // get group key
  var buttonGroup = event.target.parentNode;
  var filterGroup = buttonGroup.getAttribute('data-filter-group');
  // set filter for group
  filters[ filterGroup ] = event.target.getAttribute('data-filter');
  // arrange, and use filter fn
  iso.arrange();
});

// change is-checked class on buttons
var buttonGroups = document.querySelectorAll('.button-group');
for ( var i=0; i < buttonGroups.length; i++ ) {
  var buttonGroup = buttonGroups[i];
  radioButtonGroup( buttonGroup );
}

function radioButtonGroup( buttonGroup ) {
  buttonGroup.addEventListener( 'click', function( event ) {
    // only work with buttons
    if ( !matchesSelector( event.target, 'button' ) ) {
      return;
    }
    buttonGroup.querySelector('.is-checked').classList.remove('is-checked');
    event.target.classList.add('is-checked');
  });
}


              
            
!
999px

Console