Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Masonry - auto adjusting when the height of an item changes

I am using masonry in my application. Everything worked fine except when the height of the items change (like an accordion) masonry is not adjusting the layout. What can I do to fix it?

like image 360
amirnuri Avatar asked Oct 31 '12 10:10

amirnuri


People also ask

What is masonry effect?

Masonry layout is a layout method where one axis uses a typical strict grid layout, most often columns, and the other a masonry layout. On the masonry axis, rather than sticking to a strict grid with gaps being left after shorter items, the items in the following row rise up to completely fill the gaps.

What is masonry in web design?

Masonry is a grid layout based on columns. Unlike other grid layouts, it doesn't have fixed height rows. Basically, Masonry layout optimizes the use of space inside the web page by reducing any unnecessary gaps.

How do you use masonry in CSS?

To use masonry layout, one of your grid axes needs to have the value masonry . This will then be referred to as the masonry axis, the other axis will have rows or column tracks defined as normal, this will be the grid axis. The CSS below creates a four-column grid, with the rows set to masonry .


1 Answers

Whenever the items are resized, you need to tell masonary to re-layout everything:

$('.ui-accordion').bind('accordionchange', function(event, ui) {
    $('#container').masonry();
});
like image 197
Markus Jarderot Avatar answered Sep 22 '22 23:09

Markus Jarderot