Masonry not working with dynamic content

风格不统一 提交于 2019-12-06 10:04:21

You should use appended method. From docs:

Add and lay out newly appended item elements.

Look at this jsfiddle

Try to change your code to

boxHtml += tagsHtml +
        '</div>' +
    descriptionHtml +
'</div>';

var $boxHtml = $(boxHtml);

$content.append($boxHtml).masonry('appended', $boxHtml);

Adding up to Grin's answer:

You should also apply data-masonry-options='{ "columnWidth": 200, "itemSelector": ".item" }' to your #container.

<div id="content" class="js-masonry" data-masonry-options='{ "columnWidth": 200, "itemSelector": ".item" }'></div>

Like so. It might help with your comment response. I don't have the rep to answer as a comment.

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