Question

I am trying to use David DeSandro's Masonry on my blog posts and I have an anoying issue where the containers overlap. As soon as I re-size my browser window, everything works fine:

<!--The code I placed in my template head section:-->
<script src='http://desandro.github.io/imagesloaded/imagesloaded.pkgd.min.js'/>
<script src='http://masonry.desandro.com/masonry.pkgd.min.js'/>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js' type='text/javascript'/>
<b:if cond='data:blog.pageType != &quot;index&quot;'>
<script>
$(document).ready(function(){
    var $container = $(&#39;AJcontainer&#39;);
        $container.imagesLoaded( function() {
        $container.masonry({
            itemSelector: &#39;AJpost&#39;,
            });
    });
    });
</script>
</b:if>



<!--The code in my posts:-->
<div class="js-masonry" id="AJpost">
<div class="AJcontainer"><a href="*.jpg">
<img src="*.jpg" />
<div class="AJsumm">(...)</div></a>
</div>

I have searched for a solution in the past few days with no success: imagesLoaded does not seem to work, (window).load instead of (document).ready is not working either

This is the work in progress website: http://infinitywashere.blogspot.co.uk/2014/04/sketches-again.html

Any help would be very much appreciated!

Was it helpful?

Solution

Maybe problem with the JQuery syntax, try this:

$(window).load(function(){
    var $container = $('#AJpost');
    $container.imagesLoaded( function() {
        $container.masonry({
            itemSelector: '.AJcontainer'
        });
    });
});

Have a try without imagesLoaded:

$(window).load(function() {  
    var $container = $('#AJpost');
    $container.masonry({
        itemSelector: '.AJcontainer'
    });
}); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top