我在搜索流沙预过滤页面的链接时找到了这个答案,我对代码进行了一些编辑以使我的 url 更友好,数据过滤为 4 列,我想为第 1 列的项目分配一个特定的类和列 #4 的项目的另一个类,所有代码如果运行良好,除了将类分配给过滤数据的部分。请帮助我,我将非常感谢您的努力。
$(document).ready(function() {
// get the action filter option item on page load
var $filterType = $('#sidebar .filter a.active').attr('data-value');
// get and assign the ourHolder element to the
// $holder varible for use later
var $holder = $('.filter-container');
// clone all items within the pre-assigned $holder element
var $data = $holder.clone();
var $button = $('#sidebar .filter a');
var $all = $('.filter-container .part').data('type') === 'all';
// reset the active class on all the buttons
$button.removeClass('active');
// assign the class of the clicked filter option
// element to our $filterType variable
var $filtered = 'greases';
$('a[data-value=' + $filtered + ']').addClass('active dark');
var $filteredData = $data.find('.part[data-type~=' + $filtered + ']').show();
// Assigning the classes
$filteredData.removeClass('alpha omega').each(function(index) {
if (index % 4 == 0) $(this).addClass('alpha');
if (index % 4 == 3) $(this).addClass('omega');
});
// call quicksand and assign transition parameters
$holder.quicksand($filteredData, {
duration: 750,
easing: 'easeInOutQuad'
});
});