Skip to content
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

wp + masonry + imagesloaded lazyload = gap between posts #303

Open
AnonDev1312 opened this issue Mar 31, 2022 · 2 comments
Open

wp + masonry + imagesloaded lazyload = gap between posts #303

AnonDev1312 opened this issue Mar 31, 2022 · 2 comments

Comments

@AnonDev1312
Copy link

Hi,

I use a customized version of the Wordpress theme Baskerville, which uses jetpack masonry and imagesloaded lazyload.

But when it loads new posts after scrolling, there is a gap between the posts.
See it here: https://www.infolibertaire.net/
Screenshot: https://prnt.sc/l2vzru-dk5rY
Main javascript: https://infolibertaire.net/wp-content/themes/baskerville/js/global.js

If I open chrome developer console and manually type $blocks.masonry(); it fixes the issue... until I scroll down further and the layout breaks again

Any idea how I can fix this issue?

So far I found this workaround:

time=setInterval(function(){
   $blocks.masonry();
 },5000);

But it is not ideal as users can still see the glitch for a few seconds before the posts move

@Housik
Copy link

Housik commented Sep 10, 2022

try this in file masonryInitializer.js:

(function ($) {

    "use strict";

    $(document).ready(function () {
        // init Masonry
        var $grid = $('.msnry-grid').masonry({
            itemSelector: '.msnry-grid-item',
            columnWidth: '.msnry-grid-sizer',
            percentPosition: true,
        });

        // layout Masonry after each image loads
        $grid.find('[loading="lazy"]').on('load', function() {
            $('.msnry-grid').masonry('layout');
        })
    });

})(jQuery);

@refactorsaurusrex
Copy link

@Housik Ahhhh, finally the answer I've been looking for. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants