Skip to content

Instantly share code, notes, and snippets.

@FlowFX
Created August 7, 2017 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlowFX/7a6a076f9da6ed90e7dda1fa9a190065 to your computer and use it in GitHub Desktop.
Save FlowFX/7a6a076f9da6ed90e7dda1fa9a190065 to your computer and use it in GitHub Desktop.
$( function() {
// init Isotope
var $container = $('#container');
// init
$container.isotope({
// options
itemSelector: '.item',
// layoutMode
masonry: {
columnWidth: '.item'/2
}
});
// store filter for each group
var filters = {};
$('#filters').on( 'click', '.btn', function() {
var $this = $(this);
// get group key
var $buttonGroup = $this.parents('.btn-group');
var filterGroup = $buttonGroup.attr('data-filter-group');
// set filter for group
filters[ filterGroup ] = $this.attr('data-filter');
// combine filters
var filterValue = '';
for ( var prop in filters ) {
filterValue += filters[ prop ];
}
// set filter for Isotope
$container.isotope({ filter: filterValue });
});
// change is-checked class on buttons
$('.btn-group').each( function( i, buttonGroup ) {
var $buttonGroup = $( buttonGroup );
$buttonGroup.on( 'click', 'button', function() {
$buttonGroup.find('.active').removeClass('active');
$( this ).addClass('active');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment