【发布时间】:2018-10-31 05:45:53
【问题描述】:
我已经建立了一个同位素网格布局来显示项目,它还使用同位素过滤来更快地对项目进行排序。
过滤工作正常,直到您尝试将下拉菜单放回其默认位置“所有服务”和“所有部门”。然后所有项目都被隐藏,当它们都应该显示时。
http://www.ellyon.co.uk/wp/projects/
编辑:这可能是 Jquery 冲突吗?我已经添加了我的 functions.php,因为我不是 100% 确定我正确地添加了脚本。
functions.php
function add_isotope() {
wp_register_script( 'isotope-init', get_template_directory_uri().'/js/isotope.js', array('jquery', 'isotope'), true );
wp_register_style( 'isotope-css', get_stylesheet_directory_uri() . '/styles/project.css' );
wp_enqueue_script('isotope-init');
wp_enqueue_style('isotope-css');
}
add_action( 'wp_enqueue_scripts', 'add_isotope' );
function modify_jquery() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js', false, '3.2.1' );
wp_enqueue_script( 'jquery' );
}
}
add_action( 'init', 'modify_jquery' );
同位素.js
// Grid
var $grid = $('.grid').isotope({
itemSelector: '.grid-item',
layoutMode: 'packery',
columnWidth: '.grid-sizer',
packery: {
gutter: '.gutter-sizer'
}
});
// state variable
var $expandedItem;
// expand when clicked
$grid.on( 'click', '.grid-item', function( event ) {
var isExpanded = $expandedItem && event.currentTarget == $expandedItem[0];
if ( isExpanded ) {
// exit if already expanded
return;
}
// un-expand previous
if ( $expandedItem ) {
$expandedItem.removeClass('gigante');
}
// set new & expand
$expandedItem = $( event.currentTarget ).addClass('gigante');
$grid.isotope('layout');
});
$grid.on( 'click', '.close-button button', function( event ) {
$expandedItem.removeClass('gigante');
// reset variable
$expandedItem = null;
$grid.isotope('layout');
event.stopPropagation();
});
// Select Filters
$(function() {
var $container = $('.grid'),
$select = $('div#filterGroup select');
filters = {};
$container.isotope({
itemSelector: '.grid-item'
});
$select.change(function() {
var $this = $(this);
var $optionSet = $this;
var group = $optionSet.attr('data-filter-group');
filters[group] = $this.find('option:selected').attr('data-filter-value');
var isoFilters = [];
for (var prop in filters) {
isoFilters.push(filters[prop])
}
var selector = isoFilters.join('');
$container.isotope({
filter: selector
});
return false;
});
$grid.imagesLoaded().progress( function() {
$grid.isotope('layout');
});
});
【问题讨论】:
标签: php jquery error-handling filtering jquery-isotope