【发布时间】:2017-04-21 14:33:19
【问题描述】:
我有一个带有 flexbox 的基本布局。
CSS:
.grid {
display: flex;
flex-wrap: wrap;
}
.element-item {
flex-direction: row;
width: calc(100% / 2);
}
.element-item img {
width: 100%;
height: 16em;
object-fit: cover;
}
HTML:
<div class="grid">
<div class="element-item taxonomy">
<img class="attachment-post-thumbnail" src="image-1.jpg" alt="image-1" />
<h3>Title</h3>
<h5>Taxonomy</h5>
</div>
...
</div>
很好,按钮过滤器导航也可以正常工作。但是当我在我的 .js 文件中初始化 Isotope 时,整个布局崩溃了,图像消失了,一切都堆叠在一起了。
jQuery::
// init Isotope
var $grid = $('.grid').isotope({
// options
itemSelector: '.element-item',
});
// filter items on button click
$('.filter-button-group').on( 'click', 'button', function() {
var filterValue = $(this).attr('data-filter');
$grid.isotope({ filter: filterValue });
});
Isotope 不能很好地与 Flexbox 一起“工作”吗?或者我错过了一些同位素 jQuery 选项。还是我对 Flexbox 属性不够精确?
谢谢。
jsfiddle 请求 https://jsfiddle.net/Lyqdguvz/
【问题讨论】:
-
相当肯定同位素不能真正与 Flexbox 一起使用,但指向 jsfiddle 的链接会有所帮助。
-
现在我很困惑!有用。我不知道为什么它会破坏我的 WordPress 网站。我运行的唯一其他 jQuery 和 JS 是 slick 和 lightgallery,我尝试在 function.php 和 .js 文件中对脚本和 css 进行注释。毫无头绪。
标签: javascript jquery flexbox jquery-isotope