Isotope - multiple filters example
by aybalasubramanian
HTML
<script src="http://isotope.metafizzy.co/jquery.isotope.min.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<div class="cart">
MBLEM
</div>
<div id="filters" style="margin:10px 0 0 10px">
<input type="checkbox" name="blue" value=".blue" id="blue"><label for="blue" style="margin-left:5px;margin-right: 10px"> Available</label>
<input type="checkbox" name="green" value=".green" id="green"><label for="green" style="margin-left:5px;margin-right: 10px"> Earned</label>
<input type="checkbox" name="yellow" value=".yellow" id="yellow"><label for="yellow" style="margin-left:5px;margin-right: 10px"> In Progress</label>
<input type="checkbox" name="red" value=".red" id="red"><label for="red" style="margin-left:5px;margin-right: 10px"> Retuned - needs work</label>
</div>
<div id="container">
<div class="item blue" data-toggle="tooltip" title="New York Trek 2014 : Innovator"></div>
<div class="item blue" data-toggle="tooltip" title="Design Thinking: Beginner Skill Badge"></div>
<div class="item green" data-toggle="tooltip" title="Crash Course Design Thinking"></div>
<div class="item yellow" data-toggle="tooltip" title="Innovation Storytelling Pitch"></div>
<div class="item red" data-toggle="tooltip" title="Design Thinking: Advanced"></div>
<div class="item blue" data-toggle="tooltip" title="New York Trek 2014 : Innovator"></div>
<div class="item blue" data-toggle="tooltip" title="Design Thinking: Beginner Skill Badge"></div>
<div class="item green" data-toggle="tooltip" title="Crash Course Design Thinking"></div>
<div class="item yellow" data-toggle="tooltip" title="Innovation Storytelling Pitch"></div>
<div class="item blue" data-toggle="tooltip" title="New York Trek 2014...
CSS
body {
font-family: 'Helvetica Neue', Arial, sans-serif;
}
#container {
border: 1px solid;
padding: 3px;
}
.item {
width: 170px;
height: 170px;
margin: 3px;
float: left;
border-radius: 35px;
}
.item.next {
width: 60px;
height: 60px;
border: 5px solid black;
border-radius: 35px;
}
.red { background: red; }
.blue { background: blue; }
.green { background: green; }
.yellow { background: gold; }
/* Start: Recommended Isotope styles */
/**** Isotope Filtering ****/
.isotope-item {
z-index: 2;
}
.isotope-hidden.isotope-item {
pointer-events: none;
z-index: 1;
}
/**** Isotope CSS3 transitions ****/
.isotope,
.isotope .isotope-item {
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
transition-duration: 0.8s;
}
.isotope {
-webkit-transition-property: height, width;
-moz-transition-property: height, width;
transition-property: height, width;
}
.isotope .isotope-item {
-webkit-transition-property: -webkit-transform, opacity;
-moz-transition-property: -moz-transform, opacity;
transition-property: transform, opacity;
}
/**** disabling Isotope CSS3 transitions ****/
.isotope.no-transition,
.isotope.no-transition .isotope-item,
.isotope .isotope-item.no-transition {
-webkit-transition-duration: 0s;
-moz-transition-duration: 0s;
transition-duration: 0s;
}
/* End: Recommended Isotope styles */
.cart {
overflow:hidden;
padding:10px 3px;
background: yellow;
}
JavaScript
$(function(){
$('[data-toggle="tooltip"]').tooltip({
animated: 'fade',
placement: 'bottom',
});
var $container = $('#container'),
$checkboxes = $('#filters input');
$container.isotope({
itemSelector: '.item'
});
// get Isotope instance
var isotope = $container.data('isotope');
// add even classes to every other visible item, in current order
function addEvenClasses() {
isotope.$filteredAtoms.each( function( i, elem ) {
$(elem)[ ( i % 2 ? 'addClass' : 'removeClass' ) ]('even')
});
}
$checkboxes.change(function(){
var filters = [];
// get checked checkboxes values
$checkboxes.filter(':checked').each(function(){
filters.push( this.value );
});
// ['.red', '.blue'] -> '.red, .blue'
filters = filters.join(', ');
$container.isotope({ filter: filters });
addEvenClasses();
});
$('#shuffle').click(function(){
$container.isotope('shuffle');
addEvenClasses();
});
});