我正在使用带有组合三级过滤器的 JQuery Isotope。在我遇到的所有示例中,“重置”过滤器的唯一方法是单击“全部显示”选项。
是否可以通过单击选定的过滤器取消选择来“取消过滤”结果?
这是一个例子:http: //jsfiddle.net/RevConcept/suagb/
这是我的代码...
HTML
<div id="options" class="combo-filters">
<div class="option-combo location">
<ul class="filter option-set group level-one" data-filter-group="location">
<li class="hidden"><a href="#filter-location-any" data-filter-value="" class="selected">any</a>
<li><a href="#filter-location-exterior" data-filter-value=".exterior" class="trigger-two">exterior</a>
<li><a href="#filter-location-interior" data-filter-value=".interior" class="trigger-two">interior</a>
</ul>
</div>
<div class="option-combo illumination">
<ul class="filter option-set group level-two" data-filter-group="illumination">
<li class="hidden"><a href="#filter-illumination-any" data-filter-value="" class="selected">any</a>
<li><a href="#filter-illumination-illuminated" data-filter-value=".illuminated" class="trigger-three">illuminated</a>
<li><a href="#filter-illumination-non-illuminated" data-filter-value=".non-illuminated" class="trigger-three">non-illuminated</a>
</ul>
</div>
<div class="option-combo mount">
<ul class="filter option-set group level-three" data-filter-group="mount">
<li class="hidden"><a href="#filter-mount-any" data-filter-value="" class="selected">any</a>
<li><a href="#filter-mount-wall" data-filter-value=".wall">wall</a>
<li><a href="#filter-mount-ground" data-filter-value=".ground">ground</a>
</ul>
</div>
</div><!--end options-->
CSS
header nav a {
color:#666666;
}
header nav a.selected {
color:#000000;
}
JAVASCRIPT
$(function(){
var $container = $('#container'),
filters = {};
$container.isotope({
itemSelector : '.project',
masonry: {
columnWidth: 80
}
});
// filter buttons
$('.filter a').click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return;
}
var $optionSet = $this.parents('.option-set');
// change selected class
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
// store filter value in object
// i.e. filters.location = 'exterior'
var group = $optionSet.attr('data-filter-group');
filters[ group ] = $this.attr('data-filter-value');
// convert object into array
var isoFilters = [];
for ( var prop in filters ) {
isoFilters.push( filters[ prop ] )
}
var selector = isoFilters.join('');
$container.isotope({ filter: selector });
return false;
});
});