jquery - 过滤同位素网格后重新应用 jquery-match-height
问题描述
我正在使用jquery-match-height来匹配同位素布局的网格项目内的内部 div 的高度,这在同位素网格加载时工作得很好。
但是,当我过滤 grid时, matchheight 脚本不再处理 div,它们中的每一个都返回到其原始高度。
我努力了:
$grid.on( 'arrangeComplete', function() {
console.log("OK, arrangeComplete");
$.fn.matchHeight._update();
//$('.card-text').matchHeight(); //Here I tried simply re-initiating... no effect
});
我也试过:
if (!$grid.data('isotope').filteredItems.length ) {
$.fn.matchHeight._update();
}
我根本无法获得“重新开火”的匹配高度
解决方案
好的,我完全不确定这是最优雅的方法,但它确实有效。
这里的关键是意识到新代码必须在过滤器完成后运行,并且我应该只匹配可见元素的高度(因为过滤器不会删除与过滤器不匹配的项目,它只是将它们设置为“显示:无”
//Filter complete
$grid.on( 'arrangeComplete', function( event, filteredItems ) {
//matchheight on the visible items
$('.item:visible').matchHeight();
//And re-layout the grid
$grid.isotope('layout');
});
推荐阅读
- c++ - 可变参数模板:创建编译时数组
- python - jupyter notebook: NameError: name 'main' is not defined
- html - 如何在Angular 5中将文本更改为单击时输入?
- javascript - 如何将悬停规则保持在 Bootstrap 下拉按钮之上
- html-table - 如何对齐 2 个表格中的列宽?
- android - 相对布局中的 AutoCompleteTextView
- html - python烧瓶:如何在中心对齐表格
- asp.net-core - 将用户从移动设备注册到 .net 核心
- c++ - c++ lambda函数调用纯虚函数
- laravel - Laravel - vagrant - “没有指定输入文件。”