jQuery Isotope —按类别排序,但请指定先到者 [英] jQuery Isotope — sort by category, but specify which comes first
本文介绍了jQuery Isotope —按类别排序,但请指定先到者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种类型的行为,该行为与特定的类别相匹配,并将其置于列表的开头.就像过滤器一样,除非不删除其他项目.
I'm looking for a type of sort behaviour, one that would match a specific category and bring this to the front of the listing. Like a filter would, except without removing other items.
想象一下在同位素网格中的这些类别项目:
Imagine these category items in an Isotope grid:
- 红色
- 绿色
- 蓝色
- 红色
- 绿色
- 蓝色
如果我按类别排序,则会按字母顺序显示:
If I sort by category, it does so alphabetically to show:
- 蓝色
- 蓝色
- 绿色
- 绿色
- 红色
- 红色
我想要的是将特定类别浮动到最前面,例如绿色",就像这样:
What I'd like is to float a specific category to the front, e.g. "Green", like so:
- 绿色
- 绿色
- 红色
- 红色
- 蓝色
- 蓝色
这可能吗?
我尝试为每个类别添加getSortData
函数,如下所示:
I've tried adding a getSortData
function for each category like so:
green : function( $elem ) {
var $greenItems = $elem.filter('.green');
var $otherItems = $elem.filter(':not(.green)');
return $greenItems.add($otherItems);
}
// repeat for blue, red, etc
但这没用.
推荐答案
这对我有用:
green : function( $elem ) {
var isGreen = $elem.hasClass('green');
return (!isGreen?' ':'');
},
// etc
演示: http://jsfiddle.net/Yvk9q/9/
这篇关于jQuery Isotope —按类别排序,但请指定先到者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文