用同位素重新布局项目,似乎无法维持结构

发布于 2024-10-19 02:52:43 字数 509 浏览 3 评论 0原文

我一直在玩同位素 http://isotope.metafizzy.co/demos/relayout.html 并一直在尝试创建一个保持固定大小的父容器, 总是有 6 个较小的项目,并重新调整以适应第 7 个较大的项目。

这是我到目前为止在 jsfiddle 上得到的内容 http://jsfiddle.net/pedalpete/LGBg6/

我希望发生的是点击后在任何块上,任何一行中较小块的总数将为 3。

出于某种原因,无论是用户 .isotope('resize'),还是像我一样重新创建同位素,我最终会得到一个数字顶行大于 3,因此项目排序不均匀。

我原以为,诉诸之后,安排会有些静态。 有没有办法让同位素服从绑定盒的宽度和高度参数?

I've been playing about with isotope a bit
http://isotope.metafizzy.co/demos/relayout.html
and have been trying to create a parent container that remains a fixed size,
always having 6 smaller items, and reshuffling to fit the 7th larger item.

Here is what I have so far on jsfiddle
http://jsfiddle.net/pedalpete/LGBg6/

What I was hoping would happen is that after clicking on any block, the total number of smaller blocks in any one row would be 3.

For some reason, either user .isotope('resize'), or resorting and recreating the isotope as I'm doing, I end up with a number greater than 3 in the top row, so the items are not sorted evenly.

I would have thought that the arrangement would be somewhat static after resorting.
Is there a way to have isotope obey the width and height parameters of the binding box??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2024-10-26 02:52:43

请参阅 http://jsfiddle.net/desandro/S5vAG/ 了解我的解决方案。

有没有办法让同位素服从绑定盒的宽度和高度参数?

第一步是禁用 Isotope 调整容器大小。设置 resizesContainer 选项 false

现在,为了将这些块安装到容器中,有多种方法可以实现。您可以构建自己的布局模式,或者可以尝试进行排序。这是我采用的解决方案。

我还使用了不同的布局模式,fitColumns,我认为它更适合您的需求。使用 getSortData 参数,其逻辑是,如果该项目具有 large 类并且是偶数项目,则它将被推回下一列。因此,当 2、4、6 很大时,它们都会被放置在下一列中。

getSortData : {
  fitOrder : function( $item ) {
    var order,
        index = $item.index();

    if ( $item.hasClass('large') && index % 2 ) {
      order = index + 1.5;
    } else {
      order = index;
    }
    return order;
  }
},

See http://jsfiddle.net/desandro/S5vAG/ for my solution.

Is there a way to have isotope obey the width and height parameters of the binding box??

The first step is to disable Isotope resizing the container. Set the resizesContainer option false.

Now to accomplish fitting those blocks into the container, there are several ways to do this. You could build your own layoutMode, or you could try playing around with sorting. This is the solution I employed.

I also used a different layoutMode, fitColumns, which I think better suits what you're going for. Using the getSortData parameter, the logic is that if the item has a class of large AND is an even item, then it gets pushed back into the next column. So 2, 4, 6 all get placed in the next column when they are big.

getSortData : {
  fitOrder : function( $item ) {
    var order,
        index = $item.index();

    if ( $item.hasClass('large') && index % 2 ) {
      order = index + 1.5;
    } else {
      order = index;
    }
    return order;
  }
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文