问题
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 != "index"'>
<script>
$(document).ready(function(){
var $container = $('AJcontainer');
$container.imagesLoaded( function() {
$container.masonry({
itemSelector: 'AJpost',
});
});
});
</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!
回答1:
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'
});
});
来源:https://stackoverflow.com/questions/23087190/masonry-overlapping-issue