javascript - Doesn't Isotope play nice with Flexbox, or is it just me? - Stack Overflow

I have a basic layout with flexbox. CSS:.grid {display: flex;flex-wrap: wrap;}.element-item {flex-dir

I have a basic layout with 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>

All good, the button filter navigation is working too. But when I init Isotope in my .js file, the whole layout collapses, the images disappear and everything is stacked on top of each other.

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 });
});

Doesn't Isotope "work" well with Flexbox? Or am I missing some Isotope jQuery option. Or haven't I been precise enough with the Flexbox properties?

Thanks.

jsfiddle by request /

I have a basic layout with 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>

All good, the button filter navigation is working too. But when I init Isotope in my .js file, the whole layout collapses, the images disappear and everything is stacked on top of each other.

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 });
});

Doesn't Isotope "work" well with Flexbox? Or am I missing some Isotope jQuery option. Or haven't I been precise enough with the Flexbox properties?

Thanks.

jsfiddle by request https://jsfiddle/Lyqdguvz/

Share Improve this question edited Sep 20, 2016 at 9:36 asked Sep 19, 2016 at 20:20 user6285978user6285978 3
  • Pretty sure isotope does not really work with Flexbox but a link to a jsfiddle would be helpful. – Macsupport Commented Sep 20, 2016 at 0:44
  • Here you go: jsfiddle/Lyqdguvz – user6285978 Commented Sep 20, 2016 at 9:20
  • Now I'm confused! It works. I have no clue why it's breaking my WordPress site. The only other jQuery and JS I've running is slick and lightgallery, and I've tried menting them the script and css from the function.php and the .js file. Clueless. – user6285978 Commented Sep 20, 2016 at 9:23
Add a ment  | 

2 Answers 2

Reset to default 2

As far as I can tell the later versions of isotope play nicely with flex (I am currently using it with a flexbox project), but you need to add the layout mode option to your js:

// init Isotope
var $grid = $('.grid').isotope({
    // options
    itemSelector: '.element-item',
    layoutMode: 'fitRows'
});

There is also other layout mode options available - check out this resource: http://isotope.metafizzy.co/layout-modes.html

Okay I solved it.

What I forgot to include was that I had a .grid parent container #main set to display: flex and flexwrap: wrap. Removing that containers display properties solved it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745462562a4628775.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信