I'm using the jQuery plugin Masonry to load images on my site, but the majority of the time a lot of them are overlapping. I have found this to be a popular problem with the plugin and have tried various solutions, but still haven't gotten it working properly. This is what I have so far.
HTML
<div id="container" class="js-masonry" data-masonry-options='{ "itemSelector": ".item" }'>
{% for article in blog.articles %}
<div class="blog-article{% if forloop.first %} first{% endif %}{% if forloop.last %} last{% endif %} item">
<a href="{{ article.url }}">{{ article.content }}</a>
</div>
{% endfor %}
</div>
JS
$(window).load(function(){
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.item',
isAnimated: true,
});
});
});
CSS
#container {
position: relative;
}
.item {
margin: 10px;
width: 25%;
}
EDIT