我正在尝试将流沙与多个过滤器一起使用,我找到了一个很好的例子: http ://www.danieltulp.nl/work/quicksand-multiple.htm
像这样工作:
// DOMContentLoaded
$(function() {
// bind dropdowns in the form
var $filterAlpha = $('#filter select[name="alpha"]');
var $filterBeta = $('#filter select[name="beta"]');
var $filterGamma = $('#filter select[name="gamma"]');
// get the first collection
var $applications = $('#applications');
// clone applications to get a second collection
var $data = $applications.clone();
// attempt to call Quicksand on every form change
$('#filter li a').click(function() {
$(this).addClass('animate');
if ($($filterAlpha).val() == '0'){
if ($($filterBeta).val() == '0'){
if ($($filterGamma).val() == '0'){
//0-0-0
var $filteredData = $data.find('div');
} else {
//0-0-1
var $filteredData = $data.find('div[data-gamma=' + $($filterGamma).val() + ']' );
}
} else {
if ($($filterGamma).val() == '0'){
//0-1-0
var $filteredData = $data.find('div[data-beta=' + $($filterBeta).val() + ']' );
} else {
//0-1-1
var $filteredData = $data.find('div[data-beta=' + $($filterBeta).val() + ']' + 'div[data-gamma=' + $($filterGamma).val() + ']');
}
}
} else {
if ($($filterBeta).val() == '0'){
if ($($filterGamma).val() == '0'){
//1-0-0
var $filteredData = $data.find('div[data-alpha=' + $($filterAlpha).val() + ']' );
} else {
//1-0-1
var $filteredData = $data.find('div[data-alpha=' + $($filterAlpha).val() + ']' + 'div[data-gamma=' + $($filterGamma).val() + ']');
}
} else {
if ($($filterGamma).val() == '0'){
//1-1-0
var $filteredData = $data.find('div[data-alpha=' + $($filterAlpha).val() + ']' + 'div[data-beta=' + $($filterBeta).val() + ']');
} else {
//1-1-1
var $filteredData = $data.find('div[data-alpha=' + $($filterAlpha).val() + ']' + 'div[data-beta=' + $($filterBeta).val() + ']' + 'div[data-gamma=' + $($filterGamma).val() + ']');
}
}
}
// finally, call quicksand
$applications.quicksand($filteredData, {
duration: 1000,
easing: 'easeInOutQuad',
adjustHeight: 'auto'
});
});
});
和html:
<form id="filter">
<select name="alpha">
<option value="0">All items</option>
<option value="1">Pepper</option>
<option value="2">Apple</option>
</select>
<select name="beta">
<option value="0">All colours</option>
<option value="1">Red</option>
<option value="2">Green</option>
</select>
<select name="gamma">
<option value="0">All places</option>
<option value="1">Couche</option>
<option value="2">Table</option>
</select>
</form>
<div id="applications" class="image-grid">
<div class="animate" data-id="id-1" data-alpha="2" data-beta="1" data-gamma="1">
Apple<br />Red<br />Couche
</div>
<div class="animate" data-id="id-2" data-alpha="1" data-beta="1" data-gamma="2">
Pepper<br />Red<br />Table
</div>
<div class="animate" data-id="id-3" data-alpha="1" data-beta="2" data-gamma="1">
Pepper<br />Green<br />Couche
</div>
<div class="animate" data-id="id-4" data-alpha="2" data-beta="1" data-gamma="1">
Apple<br />Red<br />Couche
</div>
<div class="animate" data-id="id-5" data-alpha="1" data-beta="2" data-gamma="2">
Pepper<br />Green<br />Table
</div>
<div class="animate" data-id="id-6" data-alpha="1" data-beta="1" data-gamma="1">
Pepper<br />Red<br />Couche
</div>
<div class="animate" data-id="id-7" data-alpha="1" data-beta="2" data-gamma="2">
Pepper<br />Green<br />Table
</div>
<div class="animate" data-id="id-8" data-alpha="1" data-beta="2" data-gamma="1">
Pepper<br />Green<br />Couche
</div>
<div class="animate" data-id="id-9" data-alpha="1" data-beta="1" data-gamma="2">
Pepper<br />Red<br />Table
</div>
<div class="animate" data-id="id-10" data-alpha="2" data-beta="1" data-gamma="1">
Apple<br />Red<br />Couche
</div>
<div class="animate" data-id="id-11" data-alpha="2" data-beta="2" data-gamma="2">
Apple<br />Green<br />Table
</div>
<div class="animate" data-id="id-12" data-alpha="2" data-beta="2" data-gamma="2">
Apple<br />Green<br />Table
</div>
<div class="animate" data-id="id-13" data-alpha="1" data-beta="1" data-gamma="2">
Pepper<br />Red<br />Table
</div>
</div>
但我希望html可以像这样工作:
<ul id="filter" name="alpha">
<li value="0"><a href="#">All items</a></li>
<li value="1"><a href="#">Pepper</a></li>
<li value="2"><a href="#">Apple</a></li>
</ul>
<ul id="filter" name="beta">
<li value="0"><a href="#">All colours</a></li>
<li value="1"><a href="#">Red</a></li>
<li value="2"><a href="#">Green</a></li>
</ul>
<ul id="filter" name="gamma">
<li value="0"><a href="#">All places</a></li>
<li value="1"><a href="#">Couche</a></li>
<li value="2"><a href="#">Table</a></li>
</ul>
<div id="applications" class="image-grid">
<div class="animate" data-id="id-1" data-alpha="2" data-beta="1" data-gamma="1">
Apple<br />Red<br />Couche
</div>
<div class="animate" data-id="id-2" data-alpha="1" data-beta="1" data-gamma="2">
Pepper<br />Red<br />Table
</div>
<div class="animate" data-id="id-3" data-alpha="1" data-beta="2" data-gamma="1">
Pepper<br />Green<br />Couche
</div>
<div class="animate" data-id="id-4" data-alpha="2" data-beta="1" data-gamma="1">
Apple<br />Red<br />Couche
</div>
<div class="animate" data-id="id-5" data-alpha="1" data-beta="2" data-gamma="2">
Pepper<br />Green<br />Table
</div>
<div class="animate" data-id="id-6" data-alpha="1" data-beta="1" data-gamma="1">
Pepper<br />Red<br />Couche
</div>
<div class="animate" data-id="id-7" data-alpha="1" data-beta="2" data-gamma="2">
Pepper<br />Green<br />Table
</div>
<div class="animate" data-id="id-8" data-alpha="1" data-beta="2" data-gamma="1">
Pepper<br />Green<br />Couche
</div>
<div class="animate" data-id="id-9" data-alpha="1" data-beta="1" data-gamma="2">
Pepper<br />Red<br />Table
</div>
<div class="animate" data-id="id-10" data-alpha="2" data-beta="1" data-gamma="1">
Apple<br />Red<br />Couche
</div>
<div class="animate" data-id="id-11" data-alpha="2" data-beta="2" data-gamma="2">
Apple<br />Green<br />Table
</div>
<div class="animate" data-id="id-12" data-alpha="2" data-beta="2" data-gamma="2">
Apple<br />Green<br />Table
</div>
<div class="animate" data-id="id-13" data-alpha="1" data-beta="1" data-gamma="2">
Pepper<br />Red<br />Table
</div>
</div>
但我不知道要对 javascript 代码进行哪些更改。