desandro / masonry

:love_hotel: Cascading grid layout plugin
https://masonry.desandro.com
16.38k stars 2.11k forks source link

reloadItems - what does it actually do? #1072

Closed cloakedninjas closed 5 years ago

cloakedninjas commented 5 years ago

Not sure if this is me failing to understand, but Recollects all item elements is quite a vague method description.

My use case is that I've injected new content into a preexisting Masonry-enabled container, and I now want Masonry to adapt to the newly added items.

Masonry is doing something: screen shot 2018-11-28 at 11 10 08 It's adding position: absolute to the new children ... but nothing else.

Test case: https://codepen.io/anon/pen/qQJZpE

desandro commented 5 years ago

Almost there! The new HTML has been added to the page, all that HTML has been re-read and added to Masonry's collection of Items. The last missing piece to is layout the new items.

  grid.insertAdjacentHTML('beforeend', newItems);
  msnry.reloadItems();
  msnry.layout();

See demo https://codepen.io/desandro/pen/72c5217b212384e38c6cf7d945fb7c38/

emreordukaya commented 5 years ago

Almost there! The new HTML has been added to the page, all that HTML has been re-read and added to Masonry's collection of Items. The last missing piece to is layout the new items.

  grid.insertAdjacentHTML('beforeend', newItems);
  msnry.reloadItems();
  msnry.layout();

See demo https://codepen.io/desandro/pen/72c5217b212384e38c6cf7d945fb7c38/

Hi, I use this code. #1080 Yes masonry design ok. But only divs shown on page as an empty. I get data via script tags. Set script tags via jquery. so for excample I set 15 script tags for 15 divs. 15 scripts get data as an async. I can get data and bind but only the last row has a height. others 0 height. Then I tried this code but now all of divs is empty. I look browser as a developer, I see script tags directly. but it must be converted iframe in html.