Nesting Masonry objects

半世苍凉 提交于 2019-12-21 17:44:02

问题


I am trying to create a graph view using containers. So if: [A's -> B's -> C's] the view would show an objects c inside of Bs which are inside of As.

Something like this:

I think a masonry view is perfect for this but I can't get the nesting to work right.

Fiddle of what I have so far: http://jsfiddle.net/paulocoelho/5SxQ5/4/

I don't get why they are not alining. I also tried using CSS's column-count and column-gap but found the rendering to be extremely buggy.

Fiddle code coz I must...

var $container = $('.container');
$container.masonry({
    /*columnWidth: 200,*/
    itemSelector: '.eWrapper'
});

回答1:


Consider this.

Remove itemSelector property - if the one is set Masonry will use not only children items but all descendants that match that selector. So, for the first container (motherContainer) Masonry would try to layout ALL .wrapper elements, include those in nested .container elements.

And the key point - call Masonry on the reverted array of .container elements. From the innermost to the outermost, because Masonry changes children elements' height leaving gaps in the parent container.

var $container = $('.container');
$($container.get().reverse()).masonry({});

Just give it a try. Here is a jsfiddle. I also added C elements.



来源:https://stackoverflow.com/questions/18392884/nesting-masonry-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!