【发布时间】:2016-02-17 17:51:14
【问题描述】:
我用 jQuery isotope 和各种过滤器创建了一个页面。这是简化的 JSFiddle:
https://jsfiddle.net/itzuki87/21kfqhop/17/
如您所见,有 3 个过滤器:2 个复选框和 1 个范围滑块。如果单独使用所有过滤器都可以很好地工作,但是当我将它们组合使用时,它只适用于最后使用的过滤器。 这是因为我在使用范围滑块时使用“.show-me”类,而在使用复选框时使用其他类。
范围滑块:
$("#range").ionRangeSlider({
hide_min_max: true,
keyboard: true,
min: 0,
max: 150,
from: 20,
to: 110,
type: 'double',
step: 1,
prefix: "€",
grid: true,
onChange: function(data) {
$(".grid-item").each(function(){
price = parseInt($(this).find(".price").text(), 10);
if (data.from <= price && data.to >= price) {
$(this).addClass('show-me');
}
else {
$(this).removeClass('show-me');
}
});
$container.isotope({
itemSelector: '.grid-item',
filter: '.show-me'
});
}
});
复选框:
$checkboxes.on('change', function(){
filters = [];
$checkboxes.filter(':checked').each(function(){
filters.push(this.value);
});
filters = filters.join('');
$container.isotope({
filter: filters
});
});
如何才能使两种类型的过滤器同步工作?谢谢。
【问题讨论】:
标签: javascript jquery jquery-isotope