I have been trying to piece together masonry and moo tools lazyload however they both dont seem to go very well together although it possibly could just be because I am slightly useless at coding!
The masonry works on this page.
However when I try to put it together with lazyload it seems to totally mess up. Does anyone have any idea how to implement both plugins together?
I have spent 6 days trying to figure it out and this is my final hope ha!
Thanks
Recently, I gotta solve this for one of my website. I have tried a couple of ways and it seems working.
1. First Method:
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.item',
columnWidth: function(containerWidth){
return containerWidth / 12;
}
});
$('.item img').addClass('not-loaded');
$('.item img.not-loaded').lazyload({
effect: 'fadeIn',
load: function() {
// Disable trigger on this image
$(this).removeClass("not-loaded");
$container.masonry('reload');
}
});
$('.item img.not-loaded').trigger('scroll');
});
This method is good, but it has one disadvantage. The grid layout might not be kept the same since the time of masonry.reload() depends on each image's load time (i.e. the one supposed to be loaded first might only finish later)
2. Second Method: Look at sites like pinterest, i think, it does not follow the first method, because they have the container boxes arranged even before any image loaded, therefore, what I tried to achieve is to display just the boxes with same ratio as the images. The steps are:
{image1: [300,400],image2: [400,500]}
)http://jsfiddle.net/nathando/s3KPn/4/
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.item',
columnWidth: function(containerWidth){
return containerWidth / 12;
}
});
$('.item img').lazyload({
effect: 'fadeIn'
});
$('.item img').trigger('scroll');
});
[Edited to add the jsfiddle for the second method]
Notice:
/*display: none */
and comment display: block
for #container.fluid .item img
Cheers