1

我正在尝试将流沙与多个过滤器一起使用,我找到了一个很好的例子: 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 代码进行哪些更改。

4

1 回答 1

0

我已经使用流沙插件进行了几乎相同的开发。

在这里你可以找到我的代码和工作结果。

http://jsfiddle.net/AVnzX/

我的过滤器包含更多项目:

<form id="filter">
<select name="country" id="filterCountry">
    <option value="alle">Alle</option>
    <option value="usa">USA</option>
    <option value="germany">Germany</option>
    <option value="australia">Australia</option>
</select>
<select name="city" id="filterCity">
    <option value="alle">Alle</option>
    <option value="newyork">New York</option>
    <option value="sydney">Sydney</option>
    <option value="paris">Paris</option>
    <option value="munich">Munich</option>
    <option value="berlin">Berlin</option>
    <option value="losangeles">Los Angeles</option>
    <option value="miami">Miami</option>
    <option value="hamburg">Hamburg</option>
    <option value="frankfurt">Frankfurt</option>
    <option value="sanfrancisco">San Francisco</option>
</select>
<select name="alphabet" id="filterName">
    <option value="name">Name</option>
    <option value="country">Country</option>
    <option value="city">City</option>
</select>

于 2013-06-21T13:14:28.950 回答