-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Isotope filtering + Lazy loading #58
Comments
I spent a lot of time with this and finally found a solution! According to the docs (http://www.appelsiini.net/projects/lazyload)
With isotope sorting/filtering, this assumption lets us down. Fortunately we can handle this by increasing our failure_limit.
We can be a bit more precise than "something high", we can store the jQuery object we call .lazyload() on and use its length (more precisely we use the length-1, ensuring it is at least 0 because of lazyload checks against the value; using ++counter). if (++counter > settings.failure_limit) {
return false;
} We also need to ensure that the update method is called after we do our isotope sorting/filtering, so we trigger it using the onLayout callback Solution:var $imgs = ('img.lazy');
var $container = $('#container');
var $window = $(window);
$imgs.lazyload({
failure_limit : Math.max($imgs.length-1, 0);
});
$('#sort-asc li a').click(function() {
$container.isotope({
layoutMode: 'straightDown',
onLayout: function() {
$window.trigger("scroll");
}
})
}); Working jsFiddle |
Awesome. Thanks! |
Another way to deal with this is to set the isotope items to trigger on a custom jQuery event in addition to onScroll, and then when you select the filter you fire this custom event to each of the filtered items. |
The jsfiddle doesn't work anymore. I am having the same issue that when you filter to a category that doesn't have any scroll bar, meaning the items are less than the window size, the items doesn't load. It's OK when there's enough space to scroll, but when you have only two or three items that is filtered and no scrollbars, it's a big problem. I edited the fiddle with new source scripts that work. This example doesn't load the two images that was filtered. Scrolling down displays the image. Here it is http://jsfiddle.net/vanduzled/2xcaj49m/ and here's a screencast of the problem: |
Have fixed the fiddle, the isotope API had been changed, and this version should work even when the imageHeight < windowHeight |
thanks for fixing the problem @acarabott. Now it works. |
I wrote a little snippet in order to refresh lazy load status and displaying items after using isotope filter/sort: https://gist.github.com/flowdee/b6e33d61d36bcb8323fa |
@acarabott I can't get your code to work, because I also have an item selector together with the container, where can I add it? |
@itzikbenh I'm not clear what you mean, can you give an example? |
@acarabott I solved it, thanks for responding. Here is the code: $(window).load(function(){ $(window).scroll(function(){ $(document).ready(function () { |
Glad you resolved it 👍 |
hi @itzikbenh
here is my code:
|
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 #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 );
}
}
});
});
The text was updated successfully, but these errors were encountered: