I've spent considerable amount of time trying to get isotope and lazy loading working together.
The issue: lazy loading works if the user scrolls down, however if the user uses the filters, the items show up on top but the images will not load.
Here is someone with the same issue, but it seems he fixed it. I tried several things but still couldnt get it working.
Here is the dicussion https://github.com/tuupola/jquery_lazyload/issues/51
Thanks alot for your help
The code I am using is as follow.
jQuery(document).ready(function($) {
$('#big_container .media_block img').each(function(index) {
var item_height = $(this).attr("height");
$(this).parent().parent().css("height",item_height);
});
$('#big_container').isotope({
itemSelector : '.item',
layoutMode : 'masonry',
masonry: {
columnWidth: 5,
},
sortBy : 'date',
sortAscending : false,
getSortData : {
date : function ( $elem ) {
return $elem.find('.date').text(); // Date format should be [Y-m-d H:i]
},
views : function( $elem ) {
return parseInt( $elem.attr('data-views'), 10 );
},
//featured : function ( $elem ) {
// return $elem.attr('data-featured');
// },
rates : function( $elem ) {
return parseInt( $elem.attr('data-rates'), 10 );
},
comments : function( $elem ) {
return parseInt( $elem.attr('data-comments'), 10 );
}
}
});
$('#sort-by li a').click(function(){
var $this = $(this);
if ($(this).parent().hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents();
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
var sortName = $(this).attr('href').slice(1);
$('#big_container').isotope({ sortBy : sortName });
return false;
});
});
To get isotope's sorting/filtering to work with lazyload you have to do the following.
Explanation
According to the docs ( http://www.appelsiini.net/projects/lazyload )
With an isotope sorted/filtered list, the page order is certainly different from the HTML so we need to adjust our
failure_limit
.As you can see we store the jQuery object so that we can use its
length-1
as our failure_limit. If you're curious as to why it islength-1
, it's because of the following check in lazyload's update method.Lazy load on other events
If you are not triggering your lazyloads on scroll, you will need to swap the "scroll" trigger for whichever event you are using.
Demo
http://jsfiddle.net/arthurc/ZnEhn/
Code for your site
I stored some of the jQuery objects in variables as they need to be re-used.