desandro / imagesloaded

:camera: JavaScript is all like "You images done yet or what?"
https://imagesloaded.desandro.com
MIT License
8.88k stars 1.15k forks source link

Combination with masonry, infinitescroll and gifs #280

Closed MrMooky closed 5 years ago

MrMooky commented 5 years ago

I'm having some trouble with posted gifs in combination with imagesloaded and masonry. Basically, this happens quite often:

screenshot 2019-02-24 at 14 51 03

screenshot 2019-02-24 at 14 50 48

The initial loading seems to work fine, but as soon as the second or third page loads with infinite-scroll, the gifs are cut off sometimes. How could I prevent this?

How my code looks like:

$.getScript("https://webdata.friendships.me/js/infinite-scroll.min.js", function() {
            $.getScript("https://webdata.friendships.me/js/masonry.js", function() {

                $grid = $('.timeline__posts__container .posts').masonry({
                    itemSelector: 'none',
                    columnWidth: '.grid__col-sizer',
                    gutter: '.grid__gutter-sizer',
                    percentPosition: true,
                    stagger: 30,
                    visibleStyle: { transform: 'translateY(0)', opacity: 1 },
                    hiddenStyle: { transform: 'translateY(100px)', opacity: 0 },
                });

                // get Masonry instance
                var msnry = $grid.data('masonry');

                // initial items reveal
                $grid.imagesLoaded( function() {
                    $grid.removeClass('are-images-unloaded');
                    $grid.masonry( 'option', { itemSelector: '.timeline__post' });
                    var $items = $grid.find('.timeline__post');
                    $grid.masonry('appended', $items);
                });

                $grid.infiniteScroll({
                    path: '.nextPage',
                    append: '.single__post',
                    outlayer: msnry,
                    status: '.page-load-status',
                    history: false,
                    hideNav: 'ul.pagination'
                });

            });
        });
desandro commented 5 years ago

Thanks for reporting this issue. Do you have a live URL I could take a look at?

MrMooky commented 5 years ago

You can see it on https://friendships.me. You can login with User and Pass 'desandro'.

desandro commented 5 years ago

Thanks for that. I didn't see the overlap in Chrome or Firefox, but I did see it in Safari. In which case, look at metafizzy/infinite-scroll#671 for some related solutions

MrMooky commented 5 years ago

Ah, great. I'll check if any workaround mentioned there works. Thanks a lot for checking and your feedback. :)