[英]Reset jQuery IsoTope Filters and Sort
I have a number of jQuery isotope filters and a sort .我有许多 jQuery 同位素过滤器和一个sort 。 All works really nicely, but I would like to create a reset button .一切都很好,但我想创建一个重置按钮。
I have tried the following (stackoverflow: reset all combination filters ), but while it does seem to reset the items (on the second click), it does not reset the filter buttons.我尝试了以下操作(stackoverflow: 重置所有组合过滤器),但是虽然它似乎确实重置了项目(第二次单击时),但它并没有重置过滤器按钮。
I can only assume you mean "it does not reset the appearance of the filter buttons" when writing我只能假设你的意思是在写作时“它不会重置过滤器按钮的外观”
[…] it does not reset the filter buttons. [...] 它不会重置过滤器按钮。
If that is the case, and the appearance of your filter-buttons is controlled by CSS-classes just like in Isotope's examples, you simply have to remove said CSS-class(es) from the filter button elements when a user clicks the "reset"-button.如果是这种情况,并且您的过滤器按钮的外观由 CSS 类控制,就像在 Isotope 的示例中一样,您只需在用户单击“重置”按钮时从过滤器按钮元素中删除所述 CSS 类“-按钮。
In the source of eg Isotope's 'Combination filters'-demonstration you'll find the following code which handles everything happening when one of the filter-buttons is clicked:在例如Isotope 的“组合过滤器”演示的源代码中,您将找到以下代码,该代码处理单击过滤器按钮之一时发生的所有事情:
// 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.color = 'red'
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;
});
The important code (hopefully) related to your question can be found in these lines:与您的问题相关的重要代码(希望如此)可以在以下几行中找到:
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.