Jquery Masonry loading over each other after Ajax div refresh

给你一囗甜甜゛ 提交于 2019-12-03 16:35:11

Okay I seemed to have solved the problem.

I obtained the masonry object by using:

var masonry = $('#issue_container').data('masonry');

Now using this method I called reloadItems() and then layout(). After first method call every item overlaps onto each other in one tile and then after calling layout() a nice masonry layout is formed. The animation of moving from top-left corner into a nice layout also seems nice :D.

I resolved a similar issue just now. I had an outer div (enclosing the masonry container) that was set to {display: none} in CSS, and then made visible later on using $('#...').show(); I had the same issue. When the div + container is first made visible all the elements overlap. Then when the window is re-sized it's redrawn properly.

The issue seemed to be that when the elements are first created, the size of the div is zero (cause of the display:none setting), and when the Div is displayed (.show();) the elements are already rendered for a zero height container. Hence the overlap.

I fixed this by preventing the layout from being initialized till it's made visible

$myContainer = $('#myTiles');
$myContainer.masonry({
    itemSelector: '.myTile',
    isInitLayout: false
});

and then calling layout later on (in my case on a button click) using

$myContainer.masonry();

I checked your code, and couldn't replicate the issue on my side using your css / script settings... but thought I'd share my solution in case it helps.

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