如何将自定义类添加到此 jQuery Isotope 过滤并计算同位素中过滤的项目:
$(function(){
var $container = $('#wrap-planspiel'),
filters = {};
$container.isotope({
animationEngine : 'css',
itemSelector : '.hexblock'
});
// filter buttons
$('select').change(function(){
var $this = $(this);
// store filter value in object
// i.e. filters.color = 'red'
var group = $this.attr('data-filter-group');
filters[ group ] = $this.find(':selected').attr('data-filter-value');
// console.log( $this.find(':selected') )
// convert object into array
var isoFilters = [];
for ( var prop in filters ) {
isoFilters.push( filters[ prop ] )
}
console.log(filters);
var selector = isoFilters.join('');
$container.isotope({ filter: selector });
return false;
});
$('.filter a').click(function() {
var $this = $(this);
if ( $this.hasClass('selected') ) {
return;
}
var $optionSet = $this.parents('.option-set');
// change selected class
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
var group = $this.parent().data('filter-group');
filters[ group ] = $this.data('filter-value');
var isoFilters = [];
for ( var prop in filters ) {
isoFilters.push( filters[ prop ] )
}
console.log(filters);
var selector = isoFilters.join('');
$container.isotope({ filter: selector });
return false;
});
});
有一个来自 desandro 的示例,但在重置所有过滤器后该类仍然存在:http: //jsfiddle.net/desandro/3nY9V/