最近在Github上找到一款不错的过滤/筛选插件,相似jQuery UI的slider组件,很少说,上例子。html
##jQuery UIjquery
app.jsgit
function showProducts(minPrice, maxPrice) { $("#products li").hide().filter(function() { var price = parseInt($(this).data("price"), 10); return price >= minPrice && price <= maxPrice; //根据不一样价格区间来筛选 }).show(); } $(function() { var options = { range: true, min: 0, max: 500, values: [50, 300], slide: function(event, ui) { var min = ui.values[0], max = ui.values[1]; $("#amount").val("$" + min + " - $" + max); showProducts(min, max); } }, min, max; $("#slider-range").slider(options); min = $("#slider-range").slider("values", 0); max = $("#slider-range").slider("values", 1); $("#amount").val("$" + min + " - $" + max); showProducts(min, max); });
index.htmlgithub
<!-- lang: html --> <div> <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" /> <div id="slider-range" style="width:![在此输入图片描述][1]38%"></div> <ul id="products"> <li data-price="10"> product - 10 </li> <li data-price="50"> product - 50 </li> <li data-price="100"> product - 100 </li> <li data-price="150"> product - 150 </li> <li data-price="200"> product - 200 </li> </ul> </div>
效果app
jQuery UI的官网有更多例子 -> 传送门ide
##Quicksand函数
重点来了,就是Quicksand,可移步官网看它的例子 -> 传送门动画
我的以为相对与jQuery UI,灵活性比较高,能够实现更多的定制.ui
给做为筛选项的html元素加上data-id和data-type属性以标示不一样'类型'的列表项.这一步能够和checkbox的name属性值共同做用,来筛选显示匹配项.this
而后把quicksand的源文件加载进项目里就能够直接使用(它依赖与jQuery因此jQuery文件也是要包含的).
使用
<!-- lang: js --> //简单的例子 $('YourContainer').quicksand('YourElement', { duration:800, easing:swing }); //加回调函数的例子 $('YourContainer').quicksand('YourElement', { duration:800, easing:swing },function() { //do something }); //或者直接在quicksand.js源文件里修改相关的属性.
有个值得注意的坑,就是Github上的说明说jQuery.easing这个插件是可选的(主要筛选过滤动画显示支持用),可是我试了下若是未加这个插件到项目的话是没有效果的,因此若是未能运行记得加上这个(jquery.easing)
效果