desandro / masonry

:love_hotel: Cascading grid layout plugin
https://masonry.desandro.com
16.43k stars 2.11k forks source link

Masonry items overlap #1022

Closed sharifzadesina closed 6 years ago

sharifzadesina commented 6 years ago

It some times fails like this: screenshot from 2017-12-22 23-06-18 But it always should be like this: screenshot from 2017-12-22 23-07-00

My script:

window.imagesLoaded = require('imagesloaded');
window.Masonry = require('masonry-layout');
window.InfiniteScroll = require('infinite-scroll');

InfiniteScroll.imagesLoaded = imagesLoaded;
var msnry = new Masonry('.posts-grid', {
    itemSelector: '.posts-grid-item',
    originLeft: false
});
var infScroll = new InfiniteScroll('.posts-grid', {
    path: '.pagination__next',
    hideNav: '.pagination',
    append: '.posts-grid-item',
    status: '.posts-scroller-status',
    history: false,
    outlayer: msnry,
    elementScroll: 'main'
});
sharifzadesina commented 6 years ago

It seems this is cause of a bug in imagesloaded package or infinite-scroll. I've fixed it by this code:

infScroll.on('append', function(response, path, items) {
    imagesLoaded('.posts-grid', function() {
        msnry.layout();
    });
});
StErMi commented 6 years ago

It's happening also to me but I'm not using imagesloaded nor infinite-scroll

desandro commented 6 years ago

@StErMi You likely need to use imagesLoaded. See https://masonry.desandro.com/faq.html#how-do-i-fix-overlapping-item-elements