I'm using Packery
to display a grid of images.
Here is my relevant HTML :
<div class="items">
<div class="item" style="background-image: url(http://placehold.it/1000x1000)"></div>
<div class="item" style="background-image: url(http://placehold.it/1000x1000)"></div>
<!-- 12 times in total -->
</div>
Here is the CSS :
.item{
width: 25%;
background-size: cover;
height: 300px;
}
And finally the JS :
$(function(){
$('.items').packery();
});
My problem
When the page loads, here's what I get :
Notice the scrollbars, the grid is wider than the screen.
If I open the console, resize the browser window or do anything else to trigger a refresh, it will turn into this :
The horizontal scrollbar is gone, and there's no gutter between the items - it is now working as intended.
Why aren't the items properly placed in the first place? I looked at the documentation and some pen's/fiddle's that used the plugin, and I don't see what I am missing.
I tried delaying the initial call using setTimeout()
, but it doesn't work - it only delays the time before I get what is shown in the first screenshot, I still have to resize the window or trigger the refresh manually before the items move into place.