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

Images overlapping with lazy load #1165

Open
AnonDev1312 opened this issue Feb 22, 2022 · 3 comments
Open

Images overlapping with lazy load #1165

AnonDev1312 opened this issue Feb 22, 2022 · 3 comments

Comments

@AnonDev1312
Copy link

This works (without lazy load):
https://codepen.io/jo-libertaire/pen/zYPjWYw

But images are overlapping as soon as I enable lazy load:
https://codepen.io/jo-libertaire/pen/qBVYpKB

What am I doing wrong?

@ZoeFken
Copy link

ZoeFken commented Feb 22, 2022

When I was working on a it I found that using image placeholders in the lazy laod was the way to go.
The issue is that when the masorny is created all images are needed to form the correct layout. By using a set of placeholders you circumvent this issue. Or if you feel realy bold let the masonry know all the image sizes beforehand?

@AnonDev1312
Copy link
Author

When I was working on a it I found that using image placeholders in the lazy laod was the way to go.
The problem is that all my images are different sizes so I can't use the same placeholder

@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);

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